Code

Trait Code 

Source
pub trait Code {
    // Required methods
    fn encode(&self, writer: &mut impl Write) -> Result<(), Error>;
    fn decode(reader: &mut impl Read) -> Result<Self, Error>
       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§

Source

fn encode(&self, writer: &mut impl Write) -> Result<(), Error>

Encode the object into a writer.

NOTE:

When implementing Code, if std::io::Error or bincode::Error occurs during encoding, please use Error::io_error or Error::bincode_error to convert it into Error, instead of manually creating an Error..

Source

fn decode(reader: &mut impl Read) -> Result<Self, Error>
where Self: Sized,

Decode the object from a reader.

NOTE:

When implementing Code, if std::io::Error or bincode::Error occurs during decoding, please use Error::io_error or Error::bincode_error to convert it into Error, instead of manually creating an Error..

Source

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.

Implementors§

Source§

impl<T> Code for T

Available on crate feature serde only.