cgp-serde v0.1.0
This page lists what the first release of cgp-serde provides. cgp-serde rebuilds Serde's
Serialize and Deserialize traits as components of
Context-Generic Programming (CGP), a Rust library whose macros generate traits and their
wiring. Serde lets each type fix its encoding once; cgp-serde lets each application choose it.
Released on 2025-11-01.
- Release post: Announcing cgp-serde
- Crate:
cgp-serde0.1.0 on crates.io - Tag: v0.1.0
Summary
Two components, CanSerializeValue and CanDeserializeValue, move Serde's Self into a Value
parameter. The implementing type is then a context, which picks a provider for each value type. On
top of them the release ships providers that would overlap as blanket impls of Serde's traits,
encodings for bytes and dates, a JSON layer over serde_json, and components that let a
deserializer allocate borrowed values in an arena the context holds.
Compatibility
- Minimum Rust version: 1.90.
- CGP version: requires
cgp0.6. - Crates:
cgp-serde,cgp-serde-extra,cgp-serde-json,cgp-serde-alloc, andcgp-serde-typed-arena, all at 0.1.0.
Upgrading
This is the library's first release, so there is nothing to upgrade from. Add cgp-serde beside
cgp, with the other crates whose providers your wiring names.
New features
Components
CanSerializeValue<Value>writes aValueto a SerdeSerializerwith the context as&self; its provider trait isValueSerializer, andValuemay be unsized. See the reference.CanDeserializeValue<'de, Value>reads aValuefrom a SerdeDeserializerwith the context as&self; its provider trait isValueDeserializer.UseDelegatedispatch: both components declarederive_delegate: UseDelegate<Value>, so a context wires one provider per value type through aUseDelegatetable.CanAlloc<'a, T>, incgp-serde-alloc, moves a value into storage that lives for'aand returns a reference to it; its provider trait isAllocator. SeeCanAlloc.HasArena<'a, T>, incgp-serde-typed-arena, is a getter for atyped_arena::Arena<T>on the context, withUseDelegate<T>dispatch.
Context adapters
SerializeWithContextpairs a context with a value and implements Serde'sSerializethrough the context'sCanSerializeValue, so any Serde format can write the value.DeserializeWithContextimplements Serde'sDeserializeSeedthrough the context'sCanDeserializeValue.
Providers in cgp-serde
UseSerdeuses the value's ownSerializeandDeserializeimpls.SerializeStringwrites anyAsRef<str>as a string and reads aString.SerializeByteswrites anyAsRef<[u8]>as bytes and reads anyFrom<&[u8]>;TryDeserializeBytesreads bytes throughTryFrom.SerializeWithDisplaywrites aDisplayvalue as a string, andDeserializeWithFromStrreads one back throughFromStr.SerializeFrom<T>andTrySerializeFrom<T>convert to and fromTwithIntoorTryIntoand encodeTthrough the context.SerializeDerefwrites what a reference or smart pointer points to.SerializeIteratorwrites a collection iterable by reference as a sequence, andDeserializeExtendreads a sequence into any collection that isDefaultandExtend.SerializeFieldswrites a struct that derives CGP's field list, throughHasFields, as a map with each field encoded through the context, andDeserializeRecordFieldsreads such a struct back through its optional builder.DeserializeDefault<Provider>reads an optional value with the inner provider, givingDefault::default()when the value is absent, such as a JSONnull.
Providers in the other crates
cgp-serde-extra:SerializeHexandSerializeBase64encode bytes as strings, andSerializeRfc3339DateandSerializeTimestampencode achronoDateTime<Utc>as an RFC 3339 string or a Unix timestamp.cgp-serde-json:SerializeToJsonString,DeserializeFromJsonReader, andDeserializeFromJsonStringareTryComputerproviders overserde_json, andCanDeserializeJsonString<T>adds adeserialize_json_stringmethod to every context that has an error type and can deserializeTthroughDeserializeFromJsonString.cgp-serde-alloc:DeserializeAndAllocatedeserializes a value and allocates it throughCanAlloc, producing a&'a Value.cgp-serde-typed-arena:AllocateWithArenaimplementsCanAllocwith the arena thatHasArenareaches.
An AI agent wrote this page from the release's source changes and the CGP knowledge base. Its content was verified against the library's source at the release's tag. See How AI is used in this project.