pub trait SegmentMap {
const SEGMENTS: &'static [StaticSegment];
// Provided methods
fn segment(name: &str) -> Option<StaticSegment> { ... }
fn body_size() -> u32 { ... }
fn segment_count() -> usize { ... }
fn segment_by_index(index: usize) -> StaticSegment { ... }
}Expand description
Compile-time segment layout for a zero-copy struct.
Types implementing this trait declare their byte-level field map as a constant array. This enables segment-level access with zero runtime overhead, the compiler can resolve segment offsets to immediate constants in the generated code.
§Runtime vs Compile-Time
SegmentMap= compile-time, generated from struct definitionsSegmentRegistry= runtime, stored on-chain for dynamic accounts
Both can coexist: a struct might implement SegmentMap for its fixed
fields while also using SegmentRegistry for its dynamic segments.
Required Associated Constants§
Sourceconst SEGMENTS: &'static [StaticSegment]
const SEGMENTS: &'static [StaticSegment]
All segments in this layout, ordered by offset.
Provided Methods§
Sourcefn segment(name: &str) -> Option<StaticSegment>
fn segment(name: &str) -> Option<StaticSegment>
Look up a segment by field name.
Linear scan over const array. For layouts with ≤16 fields (the norm), this compiles to a small branchless sequence.
Sourcefn segment_count() -> usize
fn segment_count() -> usize
Number of segments.
Sourcefn segment_by_index(index: usize) -> StaticSegment
fn segment_by_index(index: usize) -> StaticSegment
Look up a segment by index (zero-overhead const access).
Prefer this over segment() in generated accessor code where the
index is a compile-time constant. The compiler will resolve this to
an immediate constant load, no branching, no string comparison.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.