@@ -78,19 +78,23 @@ where
7878}
7979```
8080
81- ## ` derive_component ` Macro
81+ ## ` cgp_component ` Macro
8282
8383With the repetitive pattern, it makes sense that we should be able to
8484just define the consumer trait, and make use of Rust macros to generate
8585the remaining code. The author has published the [ ` cgp ` ] ( https://docs.rs/cgp )
86- Rust crate that provides the ` derive_component ` macro that can be used for
86+ Rust crate that provides the ` cgp_component ` attribute macro that can be used for
8787this purpose. Using the macro, the same code as above can be significantly
8888simplified to the following:
8989
9090``` rust,ignore
9191use cgp::prelude::*;
9292
93- #[derive_component(ActionPerformerComponent, ActionPerformer<Context>)]
93+ #[cgp_component {
94+ name: ActionPerformerComponent,
95+ provider: ActionPerformer,
96+ context: Context,
97+ }]
9498pub trait CanPerformAction<GenericA, GenericB, ...>:
9599 ConstraintA + ConstraintB + ...
96100{
@@ -108,11 +112,12 @@ be used to bring all CGP constructs into scope. This includes the
108112` HasComponents ` and ` DelegateComponent ` traits, which are also provided
109113by the ` cgp ` crate.
110114
111- We then use ` derive_component ` as an attribute proc macro, with two
112- arguments given to the macro. The first argument, ` ActionPerformerComponent ` ,
113- is used to define the name type. The second argument, ` ActionPerformer<Context> ` ,
114- is used as the name for the provider trait, as well as the generic type name
115- for the context.
115+ We then use ` derive_component ` as an attribute proc macro, with several
116+ key-value arguments given. The ` name ` field is used to define the component
117+ name type, which is called ` ActionPerformerComponent ` . The ` provider `
118+ field ` ActionPerformer ` is used for the name for the provider trait.
119+ The ` context ` field ` Context ` is used for the generic type name of the
120+ context when used inside the provider trait.
116121
117122## ` delegate_components ` Macro
118123
0 commit comments