You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/component-macros.md
+34-8Lines changed: 34 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -257,6 +257,38 @@ delegate_components! {
257
257
}
258
258
```
259
259
260
+
## `#[cgp_context]` Macro
261
+
262
+
The `#[cgp_context]` macro can be applied on a context struct, to automatically define the provider struct for the context and implement `HasCgpProvider` for the context.
263
+
264
+
Given the following context definition:
265
+
266
+
```rust,ignore
267
+
#[cgp_context(MyContextComponents)]
268
+
pub struct MyContext {
269
+
...
270
+
}
271
+
```
272
+
273
+
The macro will generate the following constructs:
274
+
275
+
```rust,ignore
276
+
pub struct MyContextComponents;
277
+
278
+
impl HasCgpProvider for MyContext {
279
+
type CgpProvider = MyContextComponents;
280
+
}
281
+
```
282
+
283
+
If the context provider name follows the pattern `{ContextName}Components`, then the macro attribute argument can be omitted, and the code can be simplified to:
284
+
285
+
```rust,ignore
286
+
#[cgp_context]
287
+
pub struct MyContext {
288
+
...
289
+
}
290
+
```
291
+
260
292
## `#[cgp_provider]` Macro
261
293
262
294
When implementing a provider, the `#[cgp_provider]` macro needs to be used to automatically implement the `IsProviderFor` implementation, with all constraints within the `impl` block copied over.
0 commit comments