Skip to main content

Codec

Trait Codec 

Source
pub trait Codec: Sized {
    // Required methods
    fn encode(&self) -> Result<Vec<u8>>;
    fn decode_reader(reader: &mut Reader<'_>) -> Result<Self>;

    // Provided method
    fn decode(bytes: &[u8]) -> Result<Self> { ... }
}
Expand description

Trait for encoding and decoding types to/from binary format

Required Methods§

Source

fn encode(&self) -> Result<Vec<u8>>

Encode the value to bytes

Source

fn decode_reader(reader: &mut Reader<'_>) -> Result<Self>

Decode the value from a reader

Provided Methods§

Source

fn decode(bytes: &[u8]) -> Result<Self>

Decode the value from bytes

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§