cgp_type/traits/
has_type.rs

1use cgp_component::{DelegateComponent, HasComponents, UseContext, UseDelegate};
2use cgp_component_macro::cgp_component;
3
4#[cgp_component {
5    name: TypeComponent,
6    provider: ProvideType,
7}]
8pub trait HasType<Tag> {
9    type Type;
10}
11
12pub type TypeOf<Context, Tag> = <Context as HasType<Tag>>::Type;
13
14impl<Context, Tag> ProvideType<Context, Tag> for UseContext
15where
16    Context: HasType<Tag>,
17{
18    type Type = Context::Type;
19}
20
21impl<Context, Tag, Components, Type> ProvideType<Context, Tag> for UseDelegate<Components>
22where
23    Components: DelegateComponent<Tag>,
24    Components::Delegate: ProvideType<Context, Tag, Type = Type>,
25{
26    type Type = Type;
27}