Skip to main content

ExactCodec

Trait ExactCodec 

Source
pub trait ExactCodec: Sized {
    // Required methods
    fn write(&self, out: &mut Vec<u8>);
    fn read(buf: &[u8], pos: &mut usize) -> Option<Self>;

    // Provided methods
    fn to_bytes(&self) -> Vec<u8> ⓘ { ... }
    fn from_bytes(buf: &[u8]) -> Option<Self> { ... }
}
Expand description

A canonical, self-delimiting byte encoding. See the module documentation.

Required Methods§

Source

fn write(&self, out: &mut Vec<u8>)

Source

fn read(buf: &[u8], pos: &mut usize) -> Option<Self>

Provided Methods§

Source

fn to_bytes(&self) -> Vec<u8> ⓘ

Source

fn from_bytes(buf: &[u8]) -> Option<Self>

The value buf canonically encodes, with nothing left over.

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 ExactCodec for i64

Source§

fn write(&self, out: &mut Vec<u8>)

Source§

fn read(buf: &[u8], pos: &mut usize) -> Option<Self>

Source§

impl ExactCodec for u64

Source§

fn write(&self, out: &mut Vec<u8>)

Source§

fn read(buf: &[u8], pos: &mut usize) -> Option<Self>

Implementors§