Expand description
Sized data trait implementation for Solana programs using Anchor framework
This crate provides a trait and derive macro for calculating struct sizes at compile time, which is particularly useful when working with Solana account initialization.
§Example
use sized_data::SizedData;
use anchor_lang::prelude::*;
#[derive(SizedData)]
pub struct UserAccount {
pub authority: Pubkey,
pub counter: u64,
}
#[derive(Accounts)]
pub struct Initialize<'info> {
#[account(
init,
payer = user,
space = UserAccount::size_padded()
)]
pub user_account: Account<'info, UserAccount>,
#[account(mut)]
pub user: Signer<'info>,
pub system_program: Program<'info, System>,
}
Traits§
- Sized
Data - A trait for types that can calculate their size at compile time.
Derive Macros§
- Sized
Data - Derives the
SizedData
trait for structs.