Skip to content

Commit badb3ae

Browse files
authored
Fix component macros chapter with new syntax (#15)
1 parent 5148cd2 commit badb3ae

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

Diff for: content/component-macros.md

+13-8
Original file line numberDiff line numberDiff line change
@@ -78,19 +78,23 @@ where
7878
}
7979
```
8080

81-
## `derive_component` Macro
81+
## `cgp_component` Macro
8282

8383
With the repetitive pattern, it makes sense that we should be able to
8484
just define the consumer trait, and make use of Rust macros to generate
8585
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
8787
this purpose. Using the macro, the same code as above can be significantly
8888
simplified to the following:
8989

9090
```rust,ignore
9191
use cgp::prelude::*;
9292
93-
#[derive_component(ActionPerformerComponent, ActionPerformer<Context>)]
93+
#[cgp_component {
94+
name: ActionPerformerComponent,
95+
provider: ActionPerformer,
96+
context: Context,
97+
}]
9498
pub 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
109113
by 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

Comments
 (0)