pub trait Code {
// Required methods
fn encode(&self, writer: &mut impl Write) -> Result<(), CodeError>;
fn decode(reader: &mut impl Read) -> Result<Self, CodeError>
where Self: Sized;
fn estimated_size(&self) -> usize;
}
Expand description
Encode/decode trait for key and value.
Code
is required while working with foyer hybrid cache.
Some general types has already implemented Code
by foyer, but the user needs to implement it for complex types.
Or, the user can enable serde
feature for foyer.
Then all types that implements serde::Serialize
and serde::de::DeserializeOwned
will be automatically
implemented for Code
.
Required Methods§
Sourcefn encode(&self, writer: &mut impl Write) -> Result<(), CodeError>
fn encode(&self, writer: &mut impl Write) -> Result<(), CodeError>
Encode the object into a writer.
Sourcefn decode(reader: &mut impl Read) -> Result<Self, CodeError>where
Self: Sized,
fn decode(reader: &mut impl Read) -> Result<Self, CodeError>where
Self: Sized,
Decode the object from a reader.
Sourcefn estimated_size(&self) -> usize
fn estimated_size(&self) -> usize
Estimated serialized size of the object.
The estimated serialized size is used by selector between different disk cache engines.
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.