Serializer

Trait Serializer 

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

Serialize a value to bytes

Source

fn deserialize<T: DeserializeOwned>( &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§