Skip to content

Conversation

@soareschen
Copy link
Collaborator

@soareschen soareschen commented Mar 1, 2025

Summary

This PR introduces a new check_components! macro that allows easy checking of whether a context implements a CGP component, with proper error highlighting on the failing component.

Example

Given the following code:

check_components! {
    CanUseMyApp for MyApp
    {
        FooComponent,
        BarComponent: String,
        [
            BazAComponent,
            BazBComponent
        ]:
            (u64, bool),
    }
}

The following will be generated:

trait CanUseMyApp<Component, Params>: CanUseComponent<Component, Params> {}

impl CanUseMyApp<FooComponent, ()> for MyApp {}
impl CanUseMyApp<BarComponent, String> for MyApp {}
impl CanUseMyApp<BazAComponent, (u64, bool)> for MyApp {}
impl CanUseMyApp<BazBComponent, (u64, bool)> for MyApp {}

The macro allows a list syntax similar to delegate_components!, which would multiplex the key/value entries for each item inside the list.

Background

The trait CanUseComponent<Component, Params> is implemented if a context implements the consumer for Component with the generic parameters Params.

A local trait like CanUseMyApp is declared by the macro to check for specific implementations of CanUseComponents. For example, CanUseMyApp<FooComponent, ()> is used to check for MyApp: CanUseFoo, while CanUseMyApp<BazAComponent, (u64, bool)> is used to check to MyApp: CanUseBazA<u64, bool>.

@soareschen soareschen force-pushed the check-macro branch 3 times, most recently from 56333eb to aa9a7de Compare March 1, 2025 23:04
@soareschen soareschen marked this pull request as ready for review March 2, 2025 16:58
@soareschen soareschen merged commit a58b043 into main Mar 2, 2025
5 checks passed
@soareschen soareschen deleted the check-macro branch March 2, 2025 17:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants