win_crypto_ng::helpers

Trait FromBytes

Source
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>

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 FromBytes for [u8]

Source§

const MIN_LAYOUT: Layout

Source§

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

Source§

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

Source§

impl FromBytes for [u16]

Implementors§