pub unsafe trait Pod: Copy + Sized {
// Provided methods
exec fn new_zeroed() -> Self { ... }
fn new_uninit() -> Self { ... }
fn as_bytes(&self) -> &[u8] ⓘ { ... }
fn as_bytes_mut(&mut self) -> &mut [u8] ⓘ { ... }
fn as_array_ptr_bytes<const N: usize>(
&self,
) -> (ArrayPtr<u8, N>, Tracked<&PointsTo<u8, N>>) { ... }
}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§
Sourceexec fn new_zeroed() -> Self
exec fn new_zeroed() -> Self
Creates a new instance of Pod type that is filled with zeroes.
Sourceexec fn new_uninit() -> Self
exec fn new_uninit() -> Self
Creates a new instance of Pod type with uninitialized content.
Sourceexec fn as_bytes(&self) -> r : &[u8] ⓘ
exec fn as_bytes(&self) -> r : &[u8] ⓘ
r.len() == core::mem::size_of::<Self>(),As an immutable slice of bytes.
Sourceexec fn as_bytes_mut(&mut self) -> r : &mut [u8] ⓘ
exec fn as_bytes_mut(&mut self) -> r : &mut [u8] ⓘ
r.len() == core::mem::size_of::<Self>(),As a mutable slice of bytes.
Sourceexec fn as_array_ptr_bytes<const N: usize>(
&self,
) -> slice : (ArrayPtr<u8, N>, Tracked<&PointsTo<u8, N>>)
exec fn as_array_ptr_bytes<const N: usize>( &self, ) -> slice : (ArrayPtr<u8, N>, Tracked<&PointsTo<u8, N>>)
slice.1@.value().len() == core::mem::size_of::<Self>(),slice.1@.wf(),slice.0.addr() == slice.1@.addr(),As a slice of bytes via an [ArrayPtr] (with a tracked permission).
This is the verus-flavored variant; the raw &[u8] view is Self::as_bytes.
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.