Skip to content

Conversation

@soareschen
Copy link
Collaborator

@soareschen soareschen commented Jan 31, 2026

This PR brings several improvements to the check_components! macro.

First, one can now use check_components! to directly check for the implementation of a provider on a context. For example:

check_components! {
    #[check_providers(GreetHello)]
    CanUseGreetHello for Context {
        GreeterComponent,
    }
}

This would desugar to something like:

pub trait CanUseGreetHello<Component, Params>: IsProviderFor<Component, Context, Param> {}
impl CanUseGreetHello<GreeterComponent, ()> for GreetHello {}

On the other hand, without #[check_providers], the check is done on the DelegateComponent entry of the context. That is, with:

check_components! {
    CanUseContext for Context {
        GreeterComponent,
    }
}

would be expanded into:

pub trait CanUseContext<Component, Params>: CanUseComponent<Component, Params> {}
impl CanUseContext<Component, ()> for Context {}

The use of #[check_providers] allows a provider to be checked directly, even when it is not wired with the context. For example, we can check on one or more alternative providers as follows:

check_components! {
    #[check_providers(
        GreetHello,
        GreetHi,
        SayHello,
    )]
    CanUseGreeterProviders for Context {
        GreeterComponent,
    }
}

This allows one to first verify that a provider works with a context, before wiring it to the context. This would result in less confusing error, as compared to trying to implement and wire the provider at the same time.

#[check_providers] is also useful when higher order providers are used. When multiple providers are composed, and one of the provider implementation fails, the resulting error message don't usually show which sub-provider is failing. With #[check_providers], we can check each sub-provider or sub-combination to better determine the source of error.

Aside from #[check_providers], check_components! now allows multiple check blocks to be defined. With that, multiple check modes can be done at the same time with check_components!, such as:

check_components! {
    CanUseContext for Context {
        GreeterComponent,
    }

    #[check_providers(
        GreetHello,
        GreetHi,
        SayHello,
    )]
    CanUseGreeterProviders for Context {
        GreeterComponent,
    }
}

@soareschen soareschen merged commit 157cf16 into main Jan 31, 2026
5 checks passed
@soareschen soareschen deleted the check-provider branch January 31, 2026 19:29
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