Skip to main content

HopperInitSpace

Derive Macro HopperInitSpace 

Source
#[derive(HopperInitSpace)]
Expand description

Derive const INIT_SPACE: usize = size_of::<Self>() on a struct.

Anchor-parity derive: programs that have an Anchor-shaped #[account(init, payer = X, space = 8 + Foo::INIT_SPACE)] expression can port to Hopper without reshaping the size computation. For types already declared with #[hopper::state] the same constant is emitted automatically; this derive exists for hand-authored #[repr(C)] Pod structs that want to participate in the pattern without adopting the full state attribute.

§Example

#[derive(HopperInitSpace)]
#[repr(C)]
pub struct Profile {
    pub bump: u8,
    pub authority: [u8; 32],
}

// Generated:
// impl Profile {
//     pub const INIT_SPACE: usize = core::mem::size_of::<Self>();
// }