@@ -78,19 +78,23 @@ where
78
78
}
79
79
```
80
80
81
- ## ` derive_component ` Macro
81
+ ## ` cgp_component ` Macro
82
82
83
83
With the repetitive pattern, it makes sense that we should be able to
84
84
just define the consumer trait, and make use of Rust macros to generate
85
85
the 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
87
87
this purpose. Using the macro, the same code as above can be significantly
88
88
simplified to the following:
89
89
90
90
``` rust,ignore
91
91
use cgp::prelude::*;
92
92
93
- #[derive_component(ActionPerformerComponent, ActionPerformer<Context>)]
93
+ #[cgp_component {
94
+ name: ActionPerformerComponent,
95
+ provider: ActionPerformer,
96
+ context: Context,
97
+ }]
94
98
pub trait CanPerformAction<GenericA, GenericB, ...>:
95
99
ConstraintA + ConstraintB + ...
96
100
{
@@ -108,11 +112,12 @@ be used to bring all CGP constructs into scope. This includes the
108
112
` HasComponents ` and ` DelegateComponent ` traits, which are also provided
109
113
by the ` cgp ` crate.
110
114
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.
116
121
117
122
## ` delegate_components ` Macro
118
123
0 commit comments