Skip to main content

Codec

Trait Codec 

Source
pub trait Codec: Send + Sync {
    // Required methods
    fn encode<T>(&self, value: &T) -> Result<Vec<u8>, CodecError>
       where T: Serialize;
    fn decode<T>(&self, data: &[u8]) -> Result<T, CodecError>
       where T: DeserializeOwned;
    fn content_type(&self) -> &'static str;
}
Expand description

Trait for message encoding and decoding

Required Methods§

Source

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

Encode a value to bytes

Source

fn decode<T>(&self, data: &[u8]) -> Result<T, CodecError>

Decode bytes to a value

Source

fn content_type(&self) -> &'static str

Get the content type for this codec

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§