Skip to main content

PlainData

Trait PlainData 

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

Source§

impl PlainData for f32

Source§

impl PlainData for f64

Source§

impl PlainData for i8

Source§

impl PlainData for i16

Source§

impl PlainData for i32

Source§

impl PlainData for i64

Source§

impl PlainData for i128

Source§

impl PlainData for isize

Source§

impl PlainData for u8

Source§

impl PlainData for u16

Source§

impl PlainData for u32

Source§

impl PlainData for u64

Source§

impl PlainData for u128

Source§

impl PlainData for ()

Source§

impl PlainData for usize

Source§

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

Implementors§