pub unsafe trait Pod: Copy + Sized {
// Provided methods
fn new_zeroed() -> Self { ... }
fn new_uninit() -> Self { ... }
fn from_bytes(bytes: &[u8]) -> Self { ... }
fn as_bytes(&self) -> &[u8] { ... }
fn as_bytes_mut(&mut self) -> &mut [u8] { ... }
}Expand description
A marker trait for plain old data (POD).
A POD type T:Pod supports converting to and from arbitrary
mem::size_of::<T>() bytes safely.
For example, simple primitive types like u8 and i16
are POD types. But perhaps surprisingly, bool is not POD
because Rust compiler makes implicit assumption that
a byte of bool has a value of either 0 or 1.
Interpreting a byte of value 3 has a bool value has
undefined behavior.
Safety
Marking a non-POD type as POD may cause undefined behaviors.
Provided Methods§
sourcefn new_zeroed() -> Self
fn new_zeroed() -> Self
Creates a new instance of Pod type that is filled with zeroes.
sourcefn new_uninit() -> Self
fn new_uninit() -> Self
Creates a new instance of Pod type with uninitialized content.
sourcefn from_bytes(bytes: &[u8]) -> Self
fn from_bytes(bytes: &[u8]) -> Self
Creates a new instance from the given bytes.
sourcefn as_bytes_mut(&mut self) -> &mut [u8]
fn as_bytes_mut(&mut self) -> &mut [u8]
As a mutable slice of bytes.
Object Safety§
This trait is not object safe.