Pod

Trait Pod 

Source
pub trait Pod:
    FromBytes
    + IntoBytes
    + KnownLayout
    + Immutable
    + Copy {
    // Provided methods
    fn from_bytes(bytes: &[u8]) -> Self { ... }
    fn from_first_bytes(bytes: &[u8]) -> Self { ... }
}
Expand description

A trait for plain old data (POD).

A POD type T: Pod can be safely converted to and from an arbitrary byte sequence of length size_of::<T>(). For example, primitive types such as u8 and i16 are POD types.

See the crate-level documentation for design notes and usage guidance.

Provided Methods§

Source

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

Creates a new instance from the given bytes.

§Panics

Panics if bytes.len() != size_of::<Self>().

Source

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

Creates a new instance by copying the first size_of::<Self>() bytes from bytes.

This is useful when bytes contains a larger buffer (e.g., a header followed by payload) and you only want to interpret the prefix as Self.

§Panics

Panics if bytes.len() < size_of::<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.

Implementors§