Skip to main content

Module format

Module format 

Source
Expand description

Serialization formats for cached values.

Cache backends need to serialize values to bytes for storage. The Format trait provides a dyn-compatible interface that allows backends to select serialization format at runtime.

See the crate-level documentation for a comparison of available formats.

§Why dyn-compatible?

The Backend trait returns its format via value_format() -> &dyn Format. This design enables:

  • Runtime format selection: Choose format based on configuration, not compile-time generics
  • Heterogeneous backends: Combine backends with different formats in composition layers
  • Format switching: Change serialization strategy without recompiling

Making Format dyn-compatible required a callback-based API (Format::with_serializer, Format::with_deserializer) instead of returning serializers directly. This avoids self-referential lifetime issues that would prevent trait object usage.

§Extending with Custom Formats

Implement Format to add custom serialization. Use FormatTypeId::Custom with a unique identifier string to ensure your format can be distinguished from built-in ones.

Structs§

BincodeDecoder
Opaque bincode decoder wrapper.
BincodeEncoder
Opaque bincode encoder wrapper.
BincodeFormat
Fast, compact binary serialization.
JsonFormat
JSON serialization format.
RkyvFormatrkyv_format
Rkyv format - high-performance zero-copy serialization (rkyv 0.8)
RonFormat
RON (Rusty Object Notation) serialization format.

Enums§

FormatDeserializer
Deserializer passed to Format::with_deserializer callbacks.
FormatError
Errors from serialization and deserialization operations.
FormatSerializer
Serializer passed to Format::with_serializer callbacks.
FormatTypeId
Identifies a format type for equality comparison.

Traits§

Format
Dyn-compatible serialization format.
FormatExt
Ergonomic serialization methods for Format.