Skip to content

Commit 9eb8581

Browse files
committed
Prepare for 0.1.0-beta2 release
1 parent 4d19960 commit 9eb8581

File tree

10 files changed

+80
-25
lines changed

10 files changed

+80
-25
lines changed

Cargo.lock

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,8 @@ base64 = { version = "0.22.1" }
2929
chrono = { version = "0.4.41" }
3030
typed-arena = { version = "2.0.2" }
3131

32-
cgp-serde = { version = "0.1.0-beta", path = "./crates/cgp-serde" }
33-
cgp-serde-extra = { version = "0.1.0-beta", path = "./crates/cgp-serde-extra" }
34-
cgp-serde-json = { version = "0.1.0-beta", path = "./crates/cgp-serde-json" }
35-
cgp-serde-alloc = { version = "0.1.0-beta", path = "./crates/cgp-serde-alloc" }
36-
cgp-serde-typed-arena = { version = "0.1.0-beta", path = "./crates/cgp-serde-typed-arena" }
37-
38-
[patch.crates-io]
39-
# cgp = { git = "https://github.com/contextgeneric/cgp.git" }
40-
# cgp-error-anyhow = { git = "https://github.com/contextgeneric/cgp.git" }
32+
cgp-serde = { version = "0.1.0-beta2", path = "./crates/cgp-serde" }
33+
cgp-serde-extra = { version = "0.1.0-beta2", path = "./crates/cgp-serde-extra" }
34+
cgp-serde-json = { version = "0.1.0-beta2", path = "./crates/cgp-serde-json" }
35+
cgp-serde-alloc = { version = "0.1.0-beta2", path = "./crates/cgp-serde-alloc" }
36+
cgp-serde-typed-arena = { version = "0.1.0-beta2", path = "./crates/cgp-serde-typed-arena" }

README.md

Lines changed: 62 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,64 @@
1-
# cgp-serde
1+
# cgp-serde: Modular Serialization Library for Serde
22

3-
## Overview
3+
# Announcement
44

5-
`cgp-serde` provides a context-generic version of the `serde` crate, to support modular serialization using [context-generic programming](https://contextgeneric.dev) (CGP).
5+
Read the [announcement blog post for `cgp-serde`](https://contextgeneric.dev/blog/cgp-serde-release/) for the full details.
6+
7+
# Overview
8+
9+
[**cgp-serde**](https://github.com/contextgeneric/cgp-serde) is a modular serialization library for [Serde](https://serde.rs/) that leverages the power of [**Context-Generic Programming**](https://contextgeneric.dev/) (CGP).
10+
11+
In short, `cgp-serde` extends Serde’s original [`Serialize`](https://docs.rs/serde/latest/serde/trait.Serialize.html) and [`Deserialize`](https://docs.rs/serde/latest/serde/trait.Deserialize.html) traits with CGP, making it possible to write **overlapping** or **orphaned** implementations of these traits and thus bypass the standard Rust **coherence restrictions**.
12+
13+
Furthermore, `cgp-serde` allows us to leverage the powerful [**context and capabilities**](https://tmandry.gitlab.io/blog/posts/2021-12-21-context-capabilities/) concepts in stable Rust today. This unlocks the ability to write context-dependent implementations of `Deserialize`, such as one that uses an arena allocator to deserialize a `'a T` value, a concept detailed in the proposal article.
14+
15+
16+
# Context-Generic Serialization Traits
17+
18+
The key highlight of `cgp-serde` is its introduction of context-generic versions of the Serde traits. First, the [`Serialize`](https://docs.rs/serde/latest/serde/trait.Serialize.html) trait is redefined as follows:
19+
20+
```rust
21+
#[cgp_component {
22+
provider: ValueSerializer,
23+
derive_delegate: UseDelegate<Value>,
24+
}]
25+
pub trait CanSerializeValue<Value: ?Sized> {
26+
fn serialize<S>(&self, value: &Value, serializer: S) -> Result<S::Ok, S::Error>
27+
where
28+
S: serde::Serializer;
29+
}
30+
```
31+
32+
Compared to the original `Serialize` trait, `cgp-serde` provides the `CanSerializeValue` CGP trait, which moves the original `Self` type from `Serialize` to an explicit generic parameter named `Value`. The `Self` type in `CanSerializeValue` now represents a **context** type, which can be used for **dependency injection**. The `serialize` method also accepts an extra `&self` value, making it possible to retrieve additional runtime dependencies from this context.
33+
34+
In a similar manner, `cgp-serde` defines a context-generic version of the [`Deserialize`](https://docs.rs/serde/latest/serde/trait.Deserialize.html) trait as follows:
35+
36+
```rust
37+
#[cgp_component {
38+
provider: ValueDeserializer,
39+
derive_delegate: UseDelegate<Value>,
40+
}]
41+
pub trait CanDeserializeValue<'de, Value> {
42+
fn deserialize<D>(&self, deserializer: D) -> Result<Value, D::Error>
43+
where
44+
D: serde::Deserializer<'de>;
45+
}
46+
```
47+
48+
Analogous to `CanSerializeValue`, the `CanDeserializeValue` trait moves the original `Self` type in `Deserialize` to become the `Value` generic parameter. This `deserialize` method similarly accepts an additional `&self` value, which can be utilized to supply runtime dependencies, such as an arena allocator.
49+
50+
## Provider Traits
51+
52+
In addition to having the extra `Context` parameter as the `Self` type, both `CanSerializeValue` and `CanDeserializeValue` are annotated with the `#[cgp_component]` macro, which is the mechanism that unlocks additional CGP capabilities on these traits.
53+
54+
The `provider` argument to `#[cgp_component]` automatically generates the **provider traits** called `ValueSerializer` and `ValueDeserializer`. These traits are the ones you will use for implementing **named** serialization implementations that can bypass the coherence restrictions.
55+
56+
Conversely, in CGP, we refer to the original traits `CanSerializeValue` and `CanDeserializeValue` as the **consumer traits**. The general rule of thumb is that a CGP component is **used** through its consumer trait but **implemented** using its provider trait.
57+
58+
## `UseDelegate` Provider
59+
60+
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.
61+
62+
# Learn More
63+
64+
This repository will be updated with more details later on. Until then, read the [announcement blog post for `cgp-serde`](https://contextgeneric.dev/blog/cgp-serde-release/) for the full details.

crates/cgp-serde-alloc/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "cgp-serde-alloc"
3-
version = "0.1.0-beta"
3+
version = "0.1.0-beta2"
44
edition = { workspace = true }
55
license = { workspace = true }
66
repository = { workspace = true }

crates/cgp-serde-extra/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "cgp-serde-extra"
3-
version = "0.1.0-beta"
3+
version = "0.1.0-beta2"
44
edition = { workspace = true }
55
license = { workspace = true }
66
repository = { workspace = true }

crates/cgp-serde-json/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "cgp-serde-json"
3-
version = "0.1.0-beta"
3+
version = "0.1.0-beta2"
44
edition = { workspace = true }
55
license = { workspace = true }
66
repository = { workspace = true }

crates/cgp-serde-tests/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "cgp-serde-tests"
3-
version = "0.1.0-beta"
3+
version = "0.1.0-beta2"
44
edition = { workspace = true }
55
license = { workspace = true }
66
repository = { workspace = true }

crates/cgp-serde-typed-arena/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "cgp-serde-typed-arena"
3-
version = "0.1.0-beta"
3+
version = "0.1.0-beta2"
44
edition = { workspace = true }
55
license = { workspace = true }
66
repository = { workspace = true }

crates/cgp-serde/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "cgp-serde"
3-
version = "0.1.0-beta"
3+
version = "0.1.0-beta2"
44
edition = { workspace = true }
55
license = { workspace = true }
66
repository = { workspace = true }

rust-toolchain.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[toolchain]
2-
channel = "1.90"
2+
channel = "1.91"
33
profile = "default"

0 commit comments

Comments
 (0)