Skip to content

Commit 9915145

Browse files
committed
Update to cgp v0.2.0
1 parent 508cd44 commit 9915145

File tree

3 files changed

+14
-10
lines changed

3 files changed

+14
-10
lines changed

content/_index.md

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ The separation of provider traits from consumer traits allows multiple context-g
2222
provider implementations to be defined, bypassing Rust's trait system's original restriction
2323
that forbids overlapping implementations.
2424

25-
## Expressive Ways to Write Code
25+
## Highly Expressive Code
2626

2727
With CGP, one can easily write _abstract programs_ that is generic over
2828
a 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
9292
use cgp::prelude::*;
9393

94-
#[derive_component(GreeterComponent, Greeter<Context>)]
94+
#[cgp_component {
95+
name: GreeterComponent,
96+
provider: Greeter,
97+
context: Context,
98+
}]
9599
pub trait CanGreet {
96100
fn greet(&self);
97101
}
@@ -119,7 +123,7 @@ pub struct GreetHello;
119123

120124
impl<Context> Greeter<Context> for GreetHello
121125
where
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
137141
context.
138142

139143
In this example case, the constraint
140-
`HasField<symbol!("name"), Field: Display>` means that `GreetHello`
144+
`HasField<symbol!("name"), Value: Display>` means that `GreetHello`
141145
expects `Context` to be a struct with a field named `name`, with
142146
the field type being any type that implements `Display`.
143147

144148
The trait `HasField` is a CGP getter trait for accessing fields in a
145149
struct. The `symbol!` macro is used to convert any string literal
146150
into 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
148152
the struct.
149153

150154
The `HasField` trait provides a `get_field` method,
@@ -165,7 +169,7 @@ _dependency injection_, as extra dependencies are "injected" into
165169
the provider through the context.
166170

167171
Compared 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
169173
type in `HasField`.
170174

171175
## Person Context
@@ -194,7 +198,7 @@ delegate_components! {
194198

195199
The `Person` context is defined to be a struct containing a `name` field,
196200
which 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>`,
198202
so that it can be used by `GreetHello`.
199203

200204
Additionally, we also define an empty struct `PersonComponents`, which
@@ -240,7 +244,7 @@ The method `greet` is called from the consumer trait `CanGreet`, which
240244
is implemented by `Person` via `PersonComponents`, which implements
241245
`Greeter` via delegation of `GreeterComponent` to `GreetHello`,
242246
which implements `Greeter` given that `Person` implements
243-
`HasField<symbol!("name"), Field: Display>`.
247+
`HasField<symbol!("name"), Value: Display>`.
244248
That is a lot of indirection going on!
245249

246250
Hopefully by the end of this tutorial, you have gotten a sense of how

static/greet-snippet.png

-22.3 KB
Loading

templates/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ <h3 class="title-text">
99
<span style="color: rgb(8, 155, 8)"></span> <i>Modular</i> component system
1010
</h3>
1111
<h3 class="title-text">
12-
<span style="color: rgb(8, 155, 8)"></span> <i>Expressive</i> ways to write code
12+
<span style="color: rgb(8, 155, 8)"></span> Highly <i>expressive</i> code
1313
</h3>
1414
<h3 class="title-text">
1515
<span style="color: rgb(8, 155, 8)"></span> <i>Type-Safe</i> composition
@@ -54,7 +54,7 @@ <h3 class="title-text">
5454
{% block footer %}
5555
<footer>
5656
<small class="subtext" style="text-align: center;">
57-
<a href="https://maybevoid.com">Soares Chen</a> © 2024
57+
<a href="https://maybevoid.com">MaybeVoid</a> © 2024
5858
<br />
5959
<a href="https://creativecommons.org/licenses/by-sa/4.0/?ref=chooser-v1" target="_blank" rel="license noopener noreferrer" style="display:inline-block;">
6060
CC BY-SA 4.0<img style="height:22px!important;margin-left:3px;vertical-align:text-bottom;" src="https://mirrors.creativecommons.org/presskit/icons/cc.svg?ref=chooser-v1" alt=""><img style="height:22px!important;margin-left:3px;vertical-align:text-bottom;" src="https://mirrors.creativecommons.org/presskit/icons/by.svg?ref=chooser-v1" alt=""><img style="height:22px!important;margin-left:3px;vertical-align:text-bottom;" src="https://mirrors.creativecommons.org/presskit/icons/sa.svg?ref=chooser-v1" alt="">

0 commit comments

Comments
 (0)