[][src]Trait packing::PackedBytes

pub trait PackedBytes<B>: PackedSize {
    type Error;
    fn to_bytes<En: Endian>(&self) -> Result<B, Self::Error>;
fn from_bytes<En: Endian>(bytes: B) -> Result<Self, Self::Error>; }

Trait that enables endian aware conversion to/from bytes for packable types

Mostly for primitives. Currently expected to accept/return arrays by proc macro. Benchmarking showed allocating a new 1 to 8 byte array during to/from bytes performed exactly the same as manual bit shifting or various other shenanigans.

TODO: Above perf statement likely only holds true up to a certain size. Currently nested structs and packing/unpacking them to/from &mut u8 is not supported.

Associated Types

type Error

Loading content...

Required methods

fn to_bytes<En: Endian>(&self) -> Result<B, Self::Error>

fn from_bytes<En: Endian>(bytes: B) -> Result<Self, Self::Error>

Loading content...

Implementors

impl PackedBytes<[u8; 1]> for bool[src]

type Error = Infallible

impl PackedBytes<[u8; 16]> for i128[src]

type Error = Infallible

impl PackedBytes<[u8; 16]> for u128[src]

type Error = Infallible

impl PackedBytes<[u8; 1]> for i8[src]

type Error = Infallible

impl PackedBytes<[u8; 1]> for u8[src]

type Error = Infallible

impl PackedBytes<[u8; 2]> for i16[src]

type Error = Infallible

impl PackedBytes<[u8; 2]> for u16[src]

type Error = Infallible

impl PackedBytes<[u8; 4]> for f32[src]

type Error = Infallible

impl PackedBytes<[u8; 4]> for i32[src]

type Error = Infallible

impl PackedBytes<[u8; 4]> for u32[src]

type Error = Infallible

impl PackedBytes<[u8; 8]> for f64[src]

type Error = Infallible

impl PackedBytes<[u8; 8]> for i64[src]

type Error = Infallible

impl PackedBytes<[u8; 8]> for u64[src]

type Error = Infallible

Loading content...