@@ -22,7 +22,7 @@ The separation of provider traits from consumer traits allows multiple context-g
2222provider implementations to be defined, bypassing Rust's trait system's original restriction
2323that forbids overlapping implementations.
2424
25- ## Expressive Ways to Write Code
25+ ## Highly Expressive Code
2626
2727With CGP, one can easily write _ abstract programs_ that is generic over
2828a context, together with all its associated types and methods. CGP allows such
@@ -91,7 +91,11 @@ First, we would import `cgp` and define a greeter component as follows:
9191``` rust
9292use cgp :: prelude :: * ;
9393
94- #[derive_component(GreeterComponent , Greeter <Context >)]
94+ #[cgp_component {
95+ name: GreeterComponent ,
96+ provider: Greeter ,
97+ context: Context ,
98+ }]
9599pub trait CanGreet {
96100 fn greet (& self );
97101}
@@ -119,7 +123,7 @@ pub struct GreetHello;
119123
120124impl <Context > Greeter <Context > for GreetHello
121125where
122- Context : HasField <symbol ! ("name "), Field : Display >,
126+ Context : HasField <symbol ! ("name "), Value : Display >,
123127{
124128 fn greet (context : & Context ) {
125129 println! (
@@ -137,14 +141,14 @@ but with additional constraints (or dependencies) imposed on the
137141context.
138142
139143In this example case, the constraint
140- ` HasField<symbol!("name"), Field : Display> ` means that ` GreetHello `
144+ ` HasField<symbol!("name"), Value : Display> ` means that ` GreetHello `
141145expects ` Context ` to be a struct with a field named ` name ` , with
142146the field type being any type that implements ` Display ` .
143147
144148The trait ` HasField ` is a CGP getter trait for accessing fields in a
145149struct. The ` symbol! ` macro is used to convert any string literal
146150into types, so that they can be used as type argument. The
147- associated type ` Field ` is implemented as the type of the field in
151+ associated type ` Value ` is implemented as the type of the field in
148152the struct.
149153
150154The ` HasField ` trait provides a ` get_field ` method,
@@ -165,7 +169,7 @@ _dependency injection_, as extra dependencies are "injected" into
165169the provider through the context.
166170
167171Compared to other languages, CGP can not only inject methods into
168- a provider, but also _ types_ , as we seen with the ` Field ` associated
172+ a provider, but also _ types_ , as we seen with the ` Value ` associated
169173type in ` HasField ` .
170174
171175## Person Context
@@ -194,7 +198,7 @@ delegate_components! {
194198
195199The ` Person ` context is defined to be a struct containing a ` name ` field,
196200which is of type ` String ` . The CGP macro ` derive(HasField) ` is used to
197- automatically implement ` Person: HasField<symbol!("name"), Field = String> ` ,
201+ automatically implement ` Person: HasField<symbol!("name"), Value = String> ` ,
198202so that it can be used by ` GreetHello ` .
199203
200204Additionally, we also define an empty struct ` PersonComponents ` , which
@@ -240,7 +244,7 @@ The method `greet` is called from the consumer trait `CanGreet`, which
240244is implemented by ` Person ` via ` PersonComponents ` , which implements
241245` Greeter ` via delegation of ` GreeterComponent ` to ` GreetHello ` ,
242246which implements ` Greeter ` given that ` Person ` implements
243- ` HasField<symbol!("name"), Field : Display> ` .
247+ ` HasField<symbol!("name"), Value : Display> ` .
244248That is a lot of indirection going on!
245249
246250Hopefully by the end of this tutorial, you have gotten a sense of how
0 commit comments