Skip to main content

ZeroCopy

Trait ZeroCopy 

Source
pub unsafe trait ZeroCopy:
    Pod
    + 'static
    + HopperZeroCopySealed { }
Expand description

Canonical marker for types that may be overlaid on raw bytes.

§Safety

The contract is the same four-point obligation as Pod:

  1. Every [u8; size_of::<T>()] bit pattern decodes to a valid T.
  2. align_of::<T>() == 1.
  3. T contains no padding.
  4. T contains no internal pointers or references.

§Sealing

ZeroCopy is gated behind the doc-hidden [__sealed::HopperZeroCopySealed] marker. Types authored through #[hopper::pod], #[hopper::state], hopper_layout!, or one of the framework’s own primitive wire types (WireU64, WireBool, TypedAddress<T>, etc.) stamp themselves with the seal automatically. A user bypassing the macros with a bare unsafe impl Pod does not get ZeroCopy for free. ZeroCopy is implemented only through the framework-owned sealed path.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<T> ZeroCopy for T
where T: Pod + 'static + HopperZeroCopySealed,