Expand description
Runtime-local segment primitive.
Segment is the tiny memory-contract descriptor that every segment
access routes through: {offset, size}, 8 bytes on 32-bit accounts,
Copy, const-constructable, no strings, no extra fields. It is the
runtime counterpart to hopper_core::segment_map::StaticSegment
(which carries a human-readable name for tooling), the runtime
never needs the name, so this primitive stays bare.
§Design
The finish-line audit was explicit: segment access must be
compile-time enforced and runtime cheap. Every Hopper segment
accessor should eventually lower to ptr + const_offset -> cast
and nothing more. Using this primitive means:
- macros emit
const BALANCE: Segment = Segment::body(0, 8); - call sites read
account.segment_mut_const::<u64>(&mut b, BALANCE)? - the compiler substitutes the constant, collapses the call chain,
and on Solana SBF you see one register-add over
data_ptr.
Segment never appears in an on-chain layout, it is a compile-time
description only. Use hopper_core::account::SegmentDescriptor for
bytes that travel on the wire.
Structs§
- Segment
- Compile-time descriptor of a typed byte range inside an account.
- Typed
Segment - Compile-time typed segment descriptor:
Tis the overlay type,OFFSETis the absolute byte offset from the start of account data. Zero-sized.