Skip to main content

PlainData

Trait PlainData 

pub unsafe trait PlainData: Sized { }
Expand description

Marker trait for plain data: a type for which every bit pattern of size_of::<Self>() bytes is a valid value.

§Safety

A type may implement PlainData only when every bit pattern of its size is a valid value of the type. In particular, a PlainData type must not contain bool, char, enum, reference or pointer fields, and code must not read padding bytes of a PlainData structure as values.

A PlainData type must also have harmless drop glue: writing a payload over an existing one (*output = ..) drops the bytes the guest supplied, so a type with a Drop implementation (for example a password buffer that zeroises itself on drop, like WifiPassword) must not implement PlainData.

The integer and float primitives, () and arrays of plain data implement PlainData. Use plain_data! for #[repr(C)] structures: it implements PlainData only when every field type is itself plain data and the structure has no padding, which it checks at compile time.

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§

§

impl PlainData for f32

§

impl PlainData for f64

§

impl PlainData for i8

§

impl PlainData for i16

§

impl PlainData for i32

§

impl PlainData for i64

§

impl PlainData for i128

§

impl PlainData for isize

§

impl PlainData for u8

§

impl PlainData for u16

§

impl PlainData for u32

§

impl PlainData for u64

§

impl PlainData for u128

§

impl PlainData for ()

§

impl PlainData for usize

§

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

Implementors§