Serializer

Trait Serializer 

Source
pub trait Serializer:
    Send
    + Sync
    + Clone
    + 'static {
    // Required methods
    fn name(&self) -> &str;
    fn serialize<T>(&self, value: &T) -> Result<Vec<u8>, CacheError>
       where T: Serialize;
    fn deserialize<T>(&self, bytes: &[u8]) -> Result<T, CacheError>
       where T: DeserializeOwned;
}
Expand description

Trait for pluggable serialization formats

Implement this trait to add custom serialization formats. Built-in implementations: JSON, MessagePack, Bincode.

Required Methods§

Source

fn name(&self) -> &str

Name of the serializer (for debugging/metrics)

Source

fn serialize<T>(&self, value: &T) -> Result<Vec<u8>, CacheError>
where T: Serialize,

Serialize a value to bytes

Source

fn deserialize<T>(&self, bytes: &[u8]) -> Result<T, CacheError>

Deserialize bytes to a value

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§