pub unsafe trait FromBytes {
    const MIN_LAYOUT: Layout;

    // Provided methods
    fn from_bytes(bytes: &[u8]) -> &Self { ... }
    fn from_boxed(boxed: Box<[u8]>) -> Box<Self> { ... }
}
Expand description

Marker trait for types that can be safely converted to bytes.

Required Associated Constants§

source

const MIN_LAYOUT: Layout

Specified the minimum layout requirements for the allocation:

  • is at least as big as MIN_LAYOUT.size()
  • referenced/pointed data is at least as aligned as MIN_LAYOUT.align()

For DSTs, final size should be exactly the same as the allocation’s.

Safety

In Rust, it is considered UB for pointers/references/Box<T>es to be dangling, unaligned or pointing to invalid value.

The alignment check is done using MIN_LAYOUT and thus can cause UB if implemented incorrectly.

Provided Methods§

source

fn from_bytes(bytes: &[u8]) -> &Self

source

fn from_boxed(boxed: Box<[u8]>) -> Box<Self>

Implementations on Foreign Types§

source§

impl FromBytes for [u16]

source§

impl FromBytes for [u8]

source§

const MIN_LAYOUT: Layout = _

source§

fn from_bytes(bytes: &[u8]) -> &Self

source§

fn from_boxed(boxed: Box<[u8]>) -> Box<Self>

Implementors§

source§

impl<T> FromBytes for Twhere T: Pod,

source§

impl<T: BlobLayout> FromBytes for Blob<T>