pub unsafe trait Pod: Zeroable { }Expand description
Marker for types that can be safely overlaid as &T / &mut T on raw
account bytes at any offset.
§Safety
Implementing Pod for a type T asserts all of:
- Every
[u8; size_of::<T>()]bit pattern decodes to a validT. align_of::<T>() == 1, so a reference can be formed at any byte offset without an unaligned-reference (which is UB).Tcontains no padding.Tcontains no internal pointers or references.
Native multi-byte integers (u16, u32, u64, u128, i16…i128)
are deliberately not Pod: their alignment is greater than 1, so
forming &u64 from an arbitrary account offset is undefined behaviour.
Use the alignment-1 wire types (WireU64, WireI64, …) in layouts,
and ValuePod + read_unaligned_value for by-value scalar reads.
Hopper macros mechanically enforce the field-level proof before emitting this impl. Hand-written impls carry the same unsafe contract.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".