Expand description
Unified zero-copy trait family.
The Hopper Safety Audit’s “structural” recommendation was to
consolidate Pod, FixedLayout, Projectable, SafeProjectable,
LayoutContract, header metadata, and schema export into one
coherent trait stack. This module delivers the foundation:
-
ZeroCopy, the canonical “safe to overlay on raw bytes” marker. Equivalent-in-contract toPod, which (under the defaulthopper-native-backend+bytemuckfeatures) is a sub-trait ofbytemuck::Pod + bytemuck::Zeroable.ZeroCopyis implemented for everyPodtype via a blanket impl, so existing layouts participate automatically. -
WireLayout, aZeroCopytype with a fixed wire size. Declared once viaconst WIRE_SIZE = size_of::<Self>()by default; macros may override if the in-memory and on-wire sizes diverge (none do today, but the hook is there for future compressed / tagged encodings). -
AccountLayout, aWireLayoutthat also carries Hopper’s account header identity (disc, version, wire fingerprint, schema epoch, type offset). This is the audit’s proposed top-level trait, matching its exact member list so the contract is frozen-in-place for migrations and client generation.
§Why three traits, not one
The layering mirrors a real capability hierarchy. Every account
layout is a wire layout; every wire layout is zero-copy; but not
every zero-copy type is a full account layout (u64, WireBool,
TypedAddress<T> are zero-copy but carry no header). Splitting
the traits lets generic helpers demand just what they need.
§Relation to LayoutContract
The existing crate::layout::LayoutContract trait predates this
module. LayoutContract and AccountLayout intentionally overlap:
both describe “a Hopper layout with disc/version/layout_id”.
AccountLayout is the audit-blessed name with the richer member
list; LayoutContract is kept for backward compatibility and gets
a blanket impl so any type deriving the latter automatically
satisfies the former. New authoring surfaces (the proposed
#[hopper::state] v2 expansion) should reach for AccountLayout.
Traits§
- Account
Layout - Hopper account layout identity, the top of the unified trait stack.
- Wire
Layout - A
ZeroCopytype with a compile-time-known wire size. - Zero
Copy - Canonical marker for types that may be overlaid on raw bytes.