cgp_component/traits/can_use_component.rs
1use crate::{DelegateComponent, IsProviderFor};
2
3/**
4 This is a convenient type alias that is used in the same way as [`IsProviderFor`],
5 but with the `Self` type being the `Context` type rather than the `Provider` type
6 that implements the provider trait.
7
8 The `CanUseComponent` trait is automatically implemented for any CGP `Context` type
9 that implements the `DelegateComponent<Component>` trait, and when `Contex::Delegate`
10 implements `IsProviderFor<Component, Context, Params>`.
11
12 This trait is used by `check_components!` to check whether a `Context` implements
13 a given `Component` through its provider. When there are unsatisfied constraints,
14 Rust would show the error messages from the `IsProviderFor` implementation.
15*/
16pub trait CanUseComponent<Component, Params: ?Sized = ()> {}
17
18impl<Context, Component, Params: ?Sized> CanUseComponent<Component, Params> for Context
19where
20 Context: DelegateComponent<Component>,
21 Context::Delegate: IsProviderFor<Component, Context, Params>,
22{
23}