Skip to content

Commit 644a7b5

Browse files
committed
Minor edits
1 parent 339435e commit 644a7b5

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

content/blog/2025-11-03-cgp-serde-release.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ Conversely, in CGP, we refer to the original traits `CanSerializeValue` and `Can
101101

102102
## `UseDelegate` Provider
103103

104-
Our CGP trait definitions also include a second `derive_delegate` entry within the `#[cgp_component]` macro. This entry generates a specialized `UseDelegate` provider that enables **static dispatch** of provider implementations based on the specific `Value` type. The practical application and use of `UseDelegate` will be explained in greater detail later in this article.
104+
Our CGP trait definitions also include a second `derive_delegate` entry within the `#[cgp_component]` macro. This entry generates a generic `UseDelegate` provider that enables **static dispatch** of provider implementations based on the specific `Value` type. The practical application and use of `UseDelegate` will be explained in greater detail later in this article.
105105

106106
---
107107

@@ -130,7 +130,7 @@ where
130130
}
131131
```
132132

133-
First, we define a unit struct named `UseSerde`, which acts as the *name* for our specific provider implementation. We then define a blanket trait implementation annotated with `#[cgp_impl]`, explicitly setting `UseSerde` as the provider type.
133+
First, we define a unit struct named `UseSerde`, which acts as the **name** for our provider implementation. We then define a blanket trait implementation annotated with `#[cgp_impl]`, explicitly setting `UseSerde` as the provider type.
134134

135135
Following this, we define our implementation on the `ValueSerializer` provider trait, rather than the `CanSerializeValue` consumer trait. This implementation is defined to work with any `Context` and `Value` types, provided that the target `Value` implements the original `Serialize` trait. Inside our `serialize` implementation, we ignore the `&self` context and simply call `Serialize::serialize` on the value.
136136

@@ -165,7 +165,7 @@ In the very first line, the inclusion of the `new` keyword in `#[cgp_impl]` inst
165165
struct SerializeWithDisplay;
166166
```
167167

168-
Our blanket implementation for `SerializeWithDisplay` works with any `Value` type that implements `Display`. Crucially, this implementation also requires the `Context` type to implement `CanSerializeValue<String>`. This means we use the `Context` to *look up* the serialization implementation for `String` and then employ it within our current provider implementation.
168+
Our blanket implementation for `SerializeWithDisplay` works with any `Value` type that implements `Display`. Crucially, this implementation also requires the `Context` type to implement `CanSerializeValue<String>`. This means we use the `Context` to **look up** the serialization implementation for `String` and then employ it within our current provider implementation.
169169

170170
Inside the method body, we first use `to_string` to convert our value into a standard string, and then we call `self.serialize` to serialize that string value using the context's `CanSerializeValue<String>` implementation.
171171

@@ -185,7 +185,7 @@ where
185185
}
186186
```
187187

188-
If you have any experience with Rust traits, you will immediately recognize that it is practically impossible to define this blanket `Serialize` implementation in Serde. More accurately, you are **restricted** to having **at most one** such blanket implementation of `Serialize`. Because of this restriction, it is extremely difficult to justify why this version, which uses the `Value: Display` bound, should be the *chosen* global implementation for `Serialize`.
188+
If you have any experience with Rust traits, you will immediately recognize that it is practically impossible to define this blanket `Serialize` implementation in Serde. More accurately, you are **restricted** to having **at most one** such blanket implementation of `Serialize`. Because of this restriction, it is extremely difficult to justify why this version, which uses the `Value: Display` bound, should be the *chosen* blanket implementation for `Serialize`.
189189

190190
In stark contrast, both `UseSerde` and `SerializeWithDisplay` contain **overlapping** implementations of `ValueSerializer` across *both* the `Context` and `Value` types. In vanilla Rust, this would be outright rejected, as it is perfectly possible, for instance, to have a `Value` type that implements both `Serialize` and `Display`. However, this overlapping is seamlessly enabled in CGP by utilizing the provider trait `ValueSerializer` and the powerful `#[cgp_impl]` macro. We will elaborate on the underlying mechanism in later sections.
191191

0 commit comments

Comments
 (0)