Trait ostd_pod::Pod

source ·
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§

source

fn new_zeroed() -> Self

Creates a new instance of Pod type that is filled with zeroes.

source

fn new_uninit() -> Self

Creates a new instance of Pod type with uninitialized content.

source

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

Creates a new instance from the given bytes.

source

fn as_bytes(&self) -> &[u8]

As a slice of bytes.

source

fn as_bytes_mut(&mut self) -> &mut [u8]

As a mutable slice of bytes.

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl Pod for i8

source§

impl Pod for i16

source§

impl Pod for i32

source§

impl Pod for i64

source§

impl Pod for i128

source§

impl Pod for isize

source§

impl Pod for u8

source§

impl Pod for u16

source§

impl Pod for u32

source§

impl Pod for u64

source§

impl Pod for u128

source§

impl Pod for usize

source§

impl<T: Pod, const N: usize> Pod for [T; N]

Implementors§