Skip to main content

Cacheable

Trait Cacheable 

Source
pub trait Cacheable:
    Serialize
    + DeserializeOwned
    + Send
    + Sync { }
Expand description

Marker trait for types that can be cached.

This trait abstracts serialization requirements for cached values. It has a blanket implementation for all types that satisfy the bounds, so you never need to implement it manually.

§Feature-Dependent Bounds

§Without rkyv_format (default)

Requires serde traits for JSON/binary serialization:

  • Serialize + DeserializeOwned + Send + Sync

§With rkyv_format

Additionally requires rkyv traits for zero-copy deserialization:

  • Archive - Type can be archived
  • Serialize - Can serialize to rkyv format
  • Archived: CheckBytes - Archived form can be validated
  • Archived: Deserialize - Can deserialize from archived form

§Example

// Works with default features (serde only)
#[derive(serde::Serialize, serde::Deserialize)]
struct BasicData {
    value: String,
}

// Works with rkyv_format feature
#[derive(serde::Serialize, serde::Deserialize)]
#[derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)]
#[rkyv(check_bytes)]
struct RkyvData {
    value: String,
}

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<T> Cacheable for T

Available on non-crate feature rkyv_format only.