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§
- Bincode
Decoder - Opaque bincode decoder wrapper.
- Bincode
Encoder - Opaque bincode encoder wrapper.
- Bincode
Format - Fast, compact binary serialization.
- Json
Format - JSON serialization format.
- Rkyv
Format rkyv_format - Rkyv format - high-performance zero-copy serialization (rkyv 0.8)
- RonFormat
- RON (Rusty Object Notation) serialization format.
Enums§
- Format
Deserializer - Deserializer passed to
Format::with_deserializercallbacks. - Format
Error - Errors from serialization and deserialization operations.
- Format
Serializer - Serializer passed to
Format::with_serializercallbacks. - Format
Type Id - Identifies a format type for equality comparison.