Skip to main content

hopper_segment

Macro hopper_segment 

Source
macro_rules! hopper_segment {
    (
        $(#[$attr:meta])*
        pub struct $name:ident, disc = $disc:literal
        {
            $( $seg:ident : $sty:ty = $ssize:literal ),+ $(,)?
        }
    ) => { ... };
}
Expand description

Declare a segmented account with typed segments.

Generates:

  • Segment ID constants (FNV-1a)
  • A register_segments function that initializes the segment registry
  • Per-segment accessor methods on a generated context struct
hopper_segment! {
    pub struct Treasury, disc = 3 {
        core:        TreasuryCore        = 128,
        permissions: PermissionsTable     = 256,
        history:     HistoryLog           = 512,
    }
}

// Initialize:
Treasury::init_segments(data)?;

// Read:
let core: &TreasuryCore = Treasury::load_segment::<TreasuryCore>(data, Treasury::CORE_ID)?;