Trait ncomm_utils::packing::Packable

source ·
pub trait Packable: Sized {
    // Required methods
    fn len() -> usize;
    fn pack(self, buffer: &mut [u8]) -> Result<(), PackingError>;
    fn unpack(data: &[u8]) -> Result<Self, PackingError>;
}
Expand description

Trait implemented by data to be sent over network boundaries.

Required Methods§

source

fn len() -> usize

Get the minimum necessary length of a buffer to pack this data into.

source

fn pack(self, buffer: &mut [u8]) -> Result<(), PackingError>

Pack a given piece of data into a given buffer.

Note: this format of pack was utilized to make this trait compatible with both std and no_std targets (specifically for no_std targets without alloc)

source

fn unpack(data: &[u8]) -> Result<Self, PackingError>

Unpack a given piece of data from an array of bytes

Object Safety§

This trait is not object safe.

Implementors§