Derive Macro anchor_lang::InitSpace

source ·
    // Attributes available to this derive:
Expand description

Implements a Space trait on the given struct or enum.

For types that have a variable size like String and Vec, it is necessary to indicate the size by the max_len attribute. For nested types, it is necessary to specify a size for each variable type (see example).


pub struct ExampleAccount {
    pub data: u64,
    pub string_one: String,
    #[max_len(10, 5)]
    pub nested: Vec<Vec<u8>>,

pub struct Initialize<'info> {
   pub payer: Signer<'info>,
   pub system_program: Program<'info, System>,
   #[account(init, payer = payer, space = 8 + ExampleAccount::INIT_SPACE)]
   pub data: Account<'info, ExampleAccount>,