[][src]Trait packing::Packed

pub trait Packed: PackedSize {
    type Error;
    fn pack(&self, bytes: &mut [u8]) -> Result<(), Self::Error>;
fn unpack(bytes: &[u8]) -> Result<Self, Self::Error>; }

Trait that enables packing and unpacking to/from byte slices

This is the trait that the proc macro implements on structs. Supports arbitrary field alignment - i.e. fields needn't start or end on 8-bit byte boundaries. For example, 2 bools, a 10-bit number and a 4-bit number could be packed into a pair of bytes such that the 10-bit number straddles them and doesn't align with any byte boundaries

Allowing arbitray field alignment should be zero-cost as the field definitions will all be constants.

Associated Types

type Error

Loading content...

Required methods

fn pack(&self, bytes: &mut [u8]) -> Result<(), Self::Error>

fn unpack(bytes: &[u8]) -> Result<Self, Self::Error>

Loading content...

Implementors

Loading content...