Skip to main content

CoolCodec

Trait CoolCodec 

Source
pub trait CoolCodec:
    Clone
    + Send
    + Sync
    + 'static {
    const CONTENT_TYPE: &'static str;

    // Required methods
    fn encode<T>(&self, value: &T) -> Result<Vec<u8>, CoolError>
       where T: Serialize + ?Sized;
    fn decode<T>(&self, bytes: &[u8]) -> Result<T, CoolError>
       where T: for<'de> Deserialize<'de>;
}

Required Associated Constants§

Source

const CONTENT_TYPE: &'static str

Required Methods§

Source

fn encode<T>(&self, value: &T) -> Result<Vec<u8>, CoolError>
where T: Serialize + ?Sized,

Source

fn decode<T>(&self, bytes: &[u8]) -> Result<T, CoolError>
where T: for<'de> Deserialize<'de>,

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.

Implementations on Foreign Types§

Source§

impl CoolCodec for CborCodec

Source§

const CONTENT_TYPE: &'static str = "application/cbor"

Source§

fn encode<T>(&self, value: &T) -> Result<Vec<u8>, CoolError>
where T: Serialize + ?Sized,

Source§

fn decode<T>(&self, bytes: &[u8]) -> Result<T, CoolError>
where T: for<'de> Deserialize<'de>,

Source§

impl CoolCodec for JsonCodec

Source§

const CONTENT_TYPE: &'static str = "application/json"

Source§

fn encode<T>(&self, value: &T) -> Result<Vec<u8>, CoolError>
where T: Serialize + ?Sized,

Source§

fn decode<T>(&self, bytes: &[u8]) -> Result<T, CoolError>
where T: for<'de> Deserialize<'de>,

Implementors§