pub trait CacheCodecImpl: Send + Sync {
// Required methods
fn serialize(&self, writer: &mut dyn Write) -> Result<()>;
fn deserialize(data: &Bytes) -> Result<Self>
where Self: Sized;
}Expand description
Serialization trait for cache entries.
Experimental: the serialized format is not stable and may change between releases without notice.
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:
ⓘ
impl CacheCodecImpl for MyData {
fn serialize(&self, w: &mut dyn Write) -> Result<()> { /* ... */ }
fn deserialize(data: &Bytes) -> Result<Self> { /* ... */ }
}
impl CacheKey for MyDataKey {
type ValueType = MyData;
fn codec() -> Option<CacheCodec> {
Some(CacheCodec::from_impl::<MyData>())
}
// ...
}Required Methods§
fn serialize(&self, writer: &mut dyn Write) -> Result<()>
fn deserialize(data: &Bytes) -> Result<Self>where
Self: Sized,
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".