Skip to main content

cgp-serde reference

This reference documents the public items of cgp-serde, one page per item. cgp-serde rebuilds Serde's Serialize and Deserialize as components of Context-Generic Programming (CGP), so most of its items are providers: implementations a context, the type whose wiring holds an application's choices, names in its wiring table to say how a type is encoded. The tables below list every provider by what it handles and what it asks the context for, which is what a context must also wire.

tip

New to CGP?​

A provider page assumes the wiring that basic walks through. For CGP itself, the Hello World tutorial introduces contexts, providers, and wiring, and the site's reference documents the CGP constructs these pages link to.

Serialization providers​

Every provider below implements the serializing component, the deserializing one, or both, and is imported from its crate's providers module, such as cgp_serde::providers::SerializeRecordFields. The last column is what the provider asks the context to encode in turn; see re-entrant providers.

ProviderCrateDirectionHandlesAsks the context for
UseSerdecgp-serdebothany type with Serde's traitsnothing
SerializeStringcgp-serdebothwrites any AsRef<str>; reads Stringnothing
SerializeBytescgp-serdebothwrites any AsRef<[u8]>; reads any From<&[u8]>nothing
TryDeserializeBytescgp-serdereadsany TryFrom<&[u8]>nothing
SerializeWithDisplaycgp-serdewritesany Display typeString
DeserializeWithFromStrcgp-serdereadsany FromStr type&str
SerializeFromcgp-serdebotha type converted with Intothe converted type
TrySerializeFromcgp-serdebotha type converted with TryIntothe converted type
SerializeDerefcgp-serdewritesa reference or smart pointerthe value it points to
SerializeIteratorcgp-serdewritesa collection iterable by referenceeach item it yields
DeserializeExtendcgp-serdereadsa collection that can be extendedeach item
SerializeRecordFieldscgp-serdewritesa struct with named fieldseach field's type
DeserializeRecordFieldscgp-serdereadsa struct with named fieldseach field's type
SerializeVariantFieldscgp-serdewritesan enum whose variants hold one value or none, without a lifetimeeach variant's value type, Nil for a variant with no fields
DeserializeVariantFieldscgp-serdereadsan enum whose variants hold one value or noneeach variant's value type, Nil for a variant with no fields
SerializeUnitcgp-serdebothwrites any type as a unit; reads any Default type from onenothing
DeserializeDefaultcgp-serdereadsa Default type that may be nullnothing; wraps another provider
SerializeHexcgp-serde-extrabothbytes, as hexString
SerializeBase64cgp-serde-extrabothbytes, as base64String
SerializeRfc3339Datecgp-serde-extrabothDateTime<Utc>, as an RFC 3339 stringString
SerializeTimestampcgp-serde-extrabothDateTime<Utc>, as a Unix timestampi64
DeserializeAndAllocatecgp-serde-allocreadsa reference, allocated through the contextthe owned value, and an allocator

JSON and allocation providers​

Four more providers implement other components. The JSON providers make writing and reading JSON an operation the context runs, and the arena provider implements allocation:

ProviderCrateWhat it doesAsks the context for
SerializeToJsonStringcgp-serde-jsonwrites a value as a compact JSON stringthe value's serializer, and an error type
DeserializeFromJsonReadercgp-serde-jsonreads a value from any serde_json readerthe value's deserializer, and an error type
DeserializeFromJsonStringcgp-serde-jsonreads a value from a stringwhat its inner provider asks for
AllocateWithArenacgp-serde-typed-arenaallocates into an arena held by the contextthe arena

Types and components​

The pages for the two serialization components, CanSerializeValue<Value> and CanDeserializeValue<'de, Value>, and for the arena getter HasArena, are still being written. The component design page explains the two components, and AllocateWithArena shows the arena getter in use.

Looking for a name you don't see?​

Some names belong to a construct documented under another name:

NameWhere it is documented
ValueSerializer, ValueSerializerComponentthe provider trait and wiring key of CanSerializeValue; see component design
ValueDeserializer, ValueDeserializerComponentthe provider trait and wiring key of CanDeserializeValue; see component design
SerializeJson, DeserializeJsonthe marker types that select the JSON operations; see SerializeToJsonString and DeserializeFromJsonReader
Allocator, AllocatorComponentthe provider trait and wiring key of CanAlloc
ArenaGetter, ArenaGetterComponentthe provider trait and wiring key of HasArena; see AllocateWithArena
deserialize_json_stringthe method of CanDeserializeJsonString

Where to go next​


An AI agent wrote this page using the CGP knowledge base. Its content was verified against the project's source. See How AI is used in this project.