pub unsafe trait Pod: Copy + 'static { }
Expand description
Marker trait that the given type is Plain Old Data; i.e. that it is safe to interpret any pattern of bits as a value of this type.
This is notably not true for many Rust types. e.g. interpreting the integer
value 2
as a rust bool
is undefined behavior.
We require Copy
to also rule out anything that implements Drop
.
References are inherently non-Pod, so we can require a ’static lifetime.
This is very similar in concept to bytemuck::AnyBitPattern
. However,
unlike AnyBitPattern
, this trait does not say anything about how the type
can be safely shared. e.g. while bytemuck::AnyBitPattern
disallows pointer
types, Pod
does not.
§Safety
- Any pattern of bits must be a valid value of the given type.
- The type must not contain an
UnsafeCell
, or any other structure that contains anUnsafeCell
(for exampleCell
). Otherwise the following code would have UB:ⓘlet x = Cell::new(0); let y = as_u8_slice(&x); x.set(1);
Object Safety§
This trait is not object safe.