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/blog/2025-10-12-v0.5.0-release.md
+26-27Lines changed: 26 additions & 27 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -581,11 +581,11 @@ For existing users who wish to continue using the original `HasInner` trait with
581
581
582
582
# Improvements
583
583
584
-
A couple of improvements have been made for the existing constructs in CGP. Here are a few highlights.
584
+
Several improvements have been made to existing constructs in CGP. Here are some highlights.
585
585
586
586
## Allow non-self argument in getter methods
587
587
588
-
It is now possible to use `#[cgp_getter]` and `#[cgp_auto_getter]` with types other than `Self` as the target. For example, you can now use it on a trait like:
588
+
It is now possible to use `#[cgp_getter]` and `#[cgp_auto_getter]` with target types other than `Self`. For example, you can now define a trait like:
With this, the provider `UseField<Symbol!("bar")>` would implement `FooBarGetter<Context>`, if `Context::Foo` implements `HasField<Symbol!("bar")>, Value = Context::Bar>`.
597
+
With this, the provider `UseField<Symbol!("bar")>` would implement `FooBarGetter<Context>` if `Context::Foo` implements `HasField<Symbol!("bar"), Value = Context::Bar>`.
598
598
599
599
## Support use of lifetime parameters inside CGP traits
600
600
601
-
You can now include lifetimes inside the component trait parameters. For example, `cgp-serde` defines a component that corresponds to `serde`'s `Deserialize` as follows:
601
+
Lifetimes can now be included inside component trait parameters. For instance, `cgp-serde` defines a component corresponding to `serde`'s `Deserialize` as follows:
Inside the type parameters of `IsProviderFor`, the lifetime `'de` is captured as `Life<'de>`, which is defined as:
615
+
Within the type parameters of `IsProviderFor`, the lifetime `'de` is captured as `Life<'de>`, which is defined as:
616
616
617
617
```rust
618
618
pubstructLife<'a>(pubPhantomData<*mut&'a ()>);
619
619
```
620
620
621
-
Using `Life`, we can refer to the lifetime inside of `check_components!`, such as:
621
+
Using `Life`, the lifetime can be referred to inside `check_components!`, as in the following example:
622
622
623
623
```rust
624
624
check_components! {
@@ -631,9 +631,9 @@ check_components! {
631
631
}
632
632
```
633
633
634
-
## Allow shortcut for overriding provider names in `#[cgp_type]` and `#[cgp_getter]`
634
+
## Shortcut for overriding provider names in `#[cgp_type]` and `#[cgp_getter]`
635
635
636
-
If you want to customize only the name of the provider trait in `#[cgp_type]` and `#[cgp_getter]`, you can now specify them directly without using the fully qualified key-value syntax.
636
+
You can now customize only the name of the provider trait in `#[cgp_type]` and `#[cgp_getter]` without using the fully qualified key-value syntax.
## Fix use of `new` in `delegate_components!` when keys array are used
675
+
## Fix use of `new` in `delegate_components!` when keys array is used
676
676
677
-
We have fixed a bug in `delegate_components!`, when value expressions such as `UseDelegate<new InnerComponents { ... }>`are used together with multiple keys in a list.
677
+
A bug in `delegate_components!` has been fixed that occurred when value expressions like `UseDelegate<new InnerComponents { ... }>`were used with multiple keys in a list.
678
678
679
-
For example, given the following:
679
+
For example:
680
680
681
681
```rust
682
682
delegate_components! {
@@ -693,21 +693,21 @@ delegate_components! {
693
693
}
694
694
```
695
695
696
-
Previously, the inner struct `InnerComponents` would be expanded twice. With this PR, the struct `InnerComponents`would be expanded once regardless of how many keys are in the delegate entry.
696
+
Previously, the inner struct `InnerComponents` would be expanded twice. With this fix, `InnerComponents`is expanded only once, regardless of the number of keys in the delegate entry.
697
697
698
698
# Other Updates
699
699
700
700
## RustLab Presentation
701
701
702
-
Next month in November, I will be presenting about CGP at [RustLab](https://rustlab.it/talks/how-to-stop-fighting-with-coherence-and-start-writing-context-generic-trait-impls) in Florence, with the presentation titled [How to Stop Fighting with Coherence and Start Writing Context-Generic Trait Impls](https://rustlab.it/talks/how-to-stop-fighting-with-coherence-and-start-writing-context-generic-trait-impls).
702
+
Next month in November, I will be presenting about CGP at [RustLab](https://rustlab.it/talks/how-to-stop-fighting-with-coherence-and-start-writing-context-generic-trait-impls) in Florence. The presentation is titled [How to Stop Fighting with Coherence and Start Writing Context-Generic Trait Impls](https://rustlab.it/talks/how-to-stop-fighting-with-coherence-and-start-writing-context-generic-trait-impls).
703
703
704
-
If you are interested to attend the conference, you can use the discount code `SP20FR` for a 20% discount.
704
+
If you are interested in attending, you can use the discount code `SP20FR` for a 20% discount.
705
705
706
706
## `cgp-serde`
707
707
708
-
Together with the RustLab presentation, I am working on [`cgp-serde`](https://github.com/contextgeneric/cgp-serde) to provide an extensible version of the popular `serde` crate. Here is a sneak preview of what it is going to offer.
708
+
Alongside the RustLab presentation, I am working on [`cgp-serde`](https://github.com/contextgeneric/cgp-serde), which provides an extensible version of the popular `serde` crate. Here is a sneak preview of its capabilities.
709
709
710
-
The crate offers context-generic versions of the `Serialize` and `Deserialize` traits as follows:
710
+
The crate offers context-generic versions of the `Serialize` and `Deserialize` traits:
The `cgp-serde` traits remain compatible with the original `serde`constructs. This means that we can reuse existing `serde` implementations without needing to re-implement everything to work with`cgp-serde`.
734
+
The `cgp-serde` traits remain compatible with the original `serde`traits. This allows reuse of existing `serde` implementations without reimplementing them for`cgp-serde`.
735
735
736
-
In addition to the existing capabilities, `cgp-serde`makes it possible for us to customize how specific field types should be serialized. For example, we can customize how `Vec<u8>` or `Datetime`should be serialized, without being restricted by the coherence restrictions of the trait system.
736
+
In addition, `cgp-serde`allows customizing how specific field types are serialized. For example, `Vec<u8>` or `Datetime`can be serialized in a custom manner without being restricted by trait coherence rules.
737
737
738
-
Another key feature that is unlocked by `cgp-serde` is that it unlocks the use of the ideas behind [context and capabilities](https://tmandry.gitlab.io/blog/posts/2021-12-21-context-capabilities/), and makes them usable with `serde`. For example, here is a CGP provider implementation that allocates memory for a value type using an arena allocator provided by the context:
738
+
Another key feature of `cgp-serde` is that it enables the use of [context and capabilities](https://tmandry.gitlab.io/blog/posts/2021-12-21-context-capabilities/) patterns with `serde`. For instance, here is a provider implementation that allocates memory for a value type using an arena allocator provided by the context:
739
739
740
740
```rust
741
741
#[cgp_new_provider]
@@ -756,9 +756,9 @@ where
756
756
}
757
757
```
758
758
759
-
With that, we can for example implement a deserialization context that provides an arena allocator, and use that to deserialize into a `&'a Payload` value.
759
+
This allows the implementation of a deserialization context that provides an arena allocator and uses it to deserialize into a `&'a Value`.
760
760
761
-
Following shows an example deserializer context, together with some custom deserializer providers:
761
+
An example of a deserializer contextwith custom deserializer providers is shown below:
762
762
763
763
```rust
764
764
#[derive(CgpData)]
@@ -789,16 +789,15 @@ delegate_components! {
789
789
}
790
790
```
791
791
792
-
As we can see in the above example, in the wiring for `ValueDeserializerComponent`, we use `UseDelegate` to create a table lookup for the deserialization implementation for different value types. We first use `UseSerde` to implement deserialization using the original `Deserialize` trait from `serde`. We then use `DeserializeHex` to deserialize a hex string into `Vec<u8>` bytes.
793
792
794
-
Next, we use `DeserializeRecordFields` to deserialize each field in `Payload` by using their respective value deserializers. This is made possible with the use of `#[derive(CgpData)]` on the `Payload` struct. It also demonstrates that we don't even need to derive any serialization trait on `Payload` in order to make it serializable using `cgp-serde`.
793
+
As we can see in the above example, within the wiring for `ValueDeserializerComponent`, we use `UseDelegate` to create a table lookup for deserialization implementations corresponding to different value types. First, `UseSerde` is used to implement deserialization via the original `Deserialize` trait from `serde`. After that, `DeserializeHex` handles the conversion of a hex string into a `Vec<u8>`.
795
794
796
-
Finally, we use `DeserializeAndAllocate`to deserialize a `&'a Payload`value by allocating the payload into the arena allocator provided by the context.
795
+
Next, `DeserializeRecordFields` is applied to deserialize each field in the `Payload`struct using their respective value deserializers. This functionality is enabled by the `#[derive(CgpData)]` attribute on `Payload`. The example also illustrates that it is not necessary to derive any serialization traits on `Payload` to make it work with `cgp-serde`.
797
796
798
-
There are many more details that I skipped here, that will need to be explained further along with the official release of `cgp-serde`. The crate is almost usable already, and the final work is on preparing for the remaining documentation.
797
+
Finally, `DeserializeAndAllocate` is used to deserialize a `&'a Payload` value by allocating the payload in the arena allocator provided by the context.
799
798
800
-
I will also be demonstrating the use of `cgp-serde`at [RustLab](https://rustlab.it/talks/how-to-stop-fighting-with-coherence-and-start-writing-context-generic-trait-impls). So if you are interested to find out more, do come and join me at the conference!
799
+
There are many additional details that will be explained further with the official release of `cgp-serde`. The crate is nearly ready, with the remaining work focused on documentation. I will also demonstrate `cgp-serde`at [RustLab](https://rustlab.it/talks/how-to-stop-fighting-with-coherence-and-start-writing-context-generic-trait-impls). If you are interested in learning more, join the conference to see it in action.
801
800
802
801
# Acknowledgement
803
802
804
-
Thank you Abhishek Tripathi and Dzmitry Lahoda for [sponsoring](https://github.com/sponsors/soareschen) the development of CGP!
803
+
Thank you April Gonçalves, Abhishek Tripathi and Dzmitry Lahoda for [sponsoring](https://github.com/sponsors/soareschen) the development of CGP!
0 commit comments