Skip to main content

Module segment

Module segment 

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

FieldCapability
Zero-sized field capability: type, byte offset, semantic role, and policy.
Segment
Compile-time descriptor of a typed byte range inside an account.
TypedSegment
Compile-time typed segment descriptor: T is the overlay type, OFFSET is the absolute byte offset from the start of account data. Zero-sized.

Constants§

FIELD_POLICY_AUTHORITY_GATED
Field mutations should be gated by an admin or authority proof.
FIELD_POLICY_CHECKED_MATH
Field mutations should use checked arithmetic.
FIELD_POLICY_IMMUTABLE_AFTER_INIT
Field is intended to become immutable after initialization.
FIELD_ROLE_AUTHORITY
Field carries authority or signer identity semantics.
FIELD_ROLE_BALANCE
Field carries accounting or balance semantics.
FIELD_ROLE_DATA
Generic field role for account field capability descriptors.
FIELD_ROLE_VERSION
Field carries migration/versioning semantics.