Skip to main content

LenHeader

Trait LenHeader 

Source
pub unsafe trait LenHeader:
    Into<usize>
    + Copy
    + Ord {
    type Bytes;

    // Required methods
    fn to_le_bytes(&self) -> Self::Bytes;
    fn from_le_bytes(by: Self::Bytes) -> Self;
}
Expand description

A trait that can be used as the “header” for separating framed storage.

Framed interfaces use a u16 by default, which only requires two bytes for the header, with the limitation that the largest grant allowed is 64KiB at a time. You can also use a usize allowing the maximum platform available size.

You should not have to implement this trait.

§Safety

Do it right

Required Associated Types§

Source

type Bytes

Should be [u8; size_of::<Self>()]

Required Methods§

Source

fn to_le_bytes(&self) -> Self::Bytes

Convert Self into Self::Bytes, in little endian order

Source

fn from_le_bytes(by: Self::Bytes) -> Self

Convert Self::Bytes (which is in little endian order) to Self.

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 LenHeader for u16

Source§

type Bytes = [u8; 2]

Source§

fn to_le_bytes(&self) -> Self::Bytes

Source§

fn from_le_bytes(by: Self::Bytes) -> Self

Source§

impl LenHeader for usize

Source§

type Bytes = [u8; 8]

Source§

fn to_le_bytes(&self) -> Self::Bytes

Source§

fn from_le_bytes(by: Self::Bytes) -> Self

Implementors§