Skip to main content

Pod

Trait Pod 

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

  1. Every [u8; size_of::<T>()] bit pattern decodes to a valid T.
  2. align_of::<T>() == 1, so a reference can be formed at any byte offset without an unaligned-reference (which is UB).
  3. T contains no padding.
  4. T contains 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".

Implementations on Foreign Types§

Source§

impl Pod for ()

Source§

impl Pod for i8

Source§

impl Pod for u8

Source§

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

Implementors§