Skip to main content

Codec

Trait Codec 

Source
pub trait Codec:
    Sized
    + Default
    + Send
    + Sync
    + 'static {
    // Required methods
    fn encode<T>(&self, task: &T) -> Result<Vec<u8>, ()>
       where T: Serialize;
    fn encode_into<T>(&self, task: &T, buf: &mut Vec<u8>) -> Result<usize, ()>
       where T: Serialize;
    fn decode<'a, T>(&self, buf: &'a [u8]) -> Result<T, ()>
       where T: Deserialize<'a>;
}
Expand description

The codec is immutable, if need changing (like setting up cipher), should have inner mutablilty

Required Methods§

Source

fn encode<T>(&self, task: &T) -> Result<Vec<u8>, ()>
where T: Serialize,

Source

fn encode_into<T>(&self, task: &T, buf: &mut Vec<u8>) -> Result<usize, ()>
where T: Serialize,

sererialized the msg into buf (with std::io::Writer), and return the size written

Source

fn decode<'a, T>(&self, buf: &'a [u8]) -> Result<T, ()>
where T: Deserialize<'a>,

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§