Codec

Trait Codec 

Source
pub trait Codec {
    type Compact;
    type Error: Into<BoxDynError>;

    // Required methods
    fn encode<I>(input: I) -> Result<Self::Compact, Self::Error>
       where I: Serialize;
    fn decode<O>(input: Self::Compact) -> Result<O, Self::Error>
       where O: for<'de> Deserialize<'de>;
}
Expand description

A codec allows backends to encode and decode data

Required Associated Types§

Source

type Compact

The mode of storage by the codec

Source

type Error: Into<BoxDynError>

Error encountered by the codec

Required Methods§

Source

fn encode<I>(input: I) -> Result<Self::Compact, Self::Error>
where I: Serialize,

The encoding method

Source

fn decode<O>(input: Self::Compact) -> Result<O, Self::Error>
where O: for<'de> Deserialize<'de>,

The decoding method

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 Codec for JsonCodec<Value>

Available on crate feature json only.
Source§

impl Codec for JsonCodec<String>

Available on crate feature json only.
Source§

impl Codec for JsonCodec<Vec<u8>>

Available on crate feature json only.
Source§

impl<Compact> Codec for NoopCodec<Compact>

Source§

type Compact = Compact

Source§

type Error = Box<dyn Error + Sync + Send>