Skip to main content

CacheCodecImpl

Trait CacheCodecImpl 

Source
pub trait CacheCodecImpl: Send + Sync {
    const TYPE_ID: &'static str;
    const CURRENT_VERSION: u32;

    // Required methods
    fn serialize(&self, writer: &mut CacheEntryWriter<'_>) -> Result<()>;
    fn deserialize(reader: &mut CacheEntryReader<'_>) -> Result<Self>
       where Self: Sized;
}
Expand description

Serialization trait for cache entries.

Experimental: the serialized format is not yet covered by a stability guarantee and may change between releases. When it does stabilize, the rules are: TYPE_ID, protobuf field numbers, and enum values are append-only forever; format changes that protobuf cannot express transparently bump CURRENT_VERSION.

Implement this on concrete types that need to survive serialization through a persistent cache backend, then wire it into a CacheKey via CacheCodec::from_impl.

The envelope (magic/version/type_id/type_version) is written and validated by the CacheCodec wrapper. serialize writes only the body — a header followed by sections in a fixed, version-keyed order — and deserialize reads them back in that same order. The read sequence mirroring the write sequence for each type_version is the invariant the implementor owns.

Required Associated Constants§

Source

const TYPE_ID: &'static str

Stable identity for this entry type. Must not change once shipped. This is a deliberate author-assigned string, not std::any::type_name (which is not stable across compiler versions).

Source

const CURRENT_VERSION: u32

Body schema version this build writes. Bump when the body layout changes in a way protobuf field additions cannot express transparently (adding/removing/reordering sections, a raw-blob encoding change, etc.).

Required Methods§

Source

fn serialize(&self, writer: &mut CacheEntryWriter<'_>) -> Result<()>

Write the body: a header, then sections in a fixed order.

Source

fn deserialize(reader: &mut CacheEntryReader<'_>) -> Result<Self>
where Self: Sized,

Reconstruct from the body. Branch on reader.version() for backward compat; sections are read in write order.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§