Trait 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

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 Packable for f32

Source§

fn len() -> usize

Source§

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

Source§

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

Source§

impl Packable for f64

Source§

fn len() -> usize

Source§

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

Source§

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

Source§

impl Packable for i8

Source§

fn len() -> usize

Source§

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

Source§

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

Source§

impl Packable for i16

Source§

fn len() -> usize

Source§

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

Source§

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

Source§

impl Packable for i32

Source§

fn len() -> usize

Source§

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

Source§

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

Source§

impl Packable for i64

Source§

fn len() -> usize

Source§

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

Source§

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

Source§

impl Packable for i128

Source§

fn len() -> usize

Source§

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

Source§

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

Source§

impl Packable for isize

Source§

fn len() -> usize

Source§

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

Source§

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

Source§

impl Packable for u8

Source§

fn len() -> usize

Source§

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

Source§

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

Source§

impl Packable for u16

Source§

fn len() -> usize

Source§

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

Source§

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

Source§

impl Packable for u32

Source§

fn len() -> usize

Source§

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

Source§

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

Source§

impl Packable for u64

Source§

fn len() -> usize

Source§

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

Source§

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

Source§

impl Packable for u128

Source§

fn len() -> usize

Source§

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

Source§

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

Source§

impl Packable for usize

Source§

fn len() -> usize

Source§

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

Source§

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

Implementors§