Trait Formatter

Source
pub trait Formatter: Debug {
    type Error: Error;
    type Serialized;

    const ID: &'static str;

    // Required methods
    fn serialize<T: Serialize>(
        &self,
        value: &T,
    ) -> Result<Self::Serialized, Self::Error>;
    fn deserialize<T: DeserializeOwned>(
        &self,
        value: &Self::Serialized,
    ) -> Result<T, Self::Error>;
}
Expand description

A formatter that can serialize data before storing it in a cache and deserialize it after retrieving it from the cache.

Required Associated Constants§

Source

const ID: &'static str

The unique identifier of this formatter.

Required Associated Types§

Source

type Error: Error

The error to return if serialization or deserialization fails.

Source

type Serialized

The type of serialized data.

Required Methods§

Source

fn serialize<T: Serialize>( &self, value: &T, ) -> Result<Self::Serialized, Self::Error>

Serialize a T and return a Self::Serialized.

Source

fn deserialize<T: DeserializeOwned>( &self, value: &Self::Serialized, ) -> Result<T, Self::Error>

Deserialize a Self::Serialized and return a T.

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 Formatter for JsonFormatter

Available on crate feature serde_json only.
Source§

const ID: &'static str = "json"

Source§

type Error = Error

Source§

type Serialized = String

Source§

impl Formatter for PostcardFormatter

Source§

const ID: &'static str = "postcard"

Source§

type Error = Error

Source§

type Serialized = Vec<u8>