//! Box type to save stack space. //! //! Sometimes accounts are too large for the stack, //! leading to stack violations. //! //! Boxing the account can help. //! //! # Example //! ```ignore //! #[derive(Accounts)] //! pub struct Example { //! pub my_acc: Box> //! } //! ``` use crate::{Accounts, AccountsClose, AccountsExit, ToAccountInfos, ToAccountMetas}; use solana_program::account_info::AccountInfo; use solana_program::entrypoint::ProgramResult; use solana_program::instruction::AccountMeta; use solana_program::program_error::ProgramError; use solana_program::pubkey::Pubkey; use std::collections::BTreeMap; use std::ops::Deref; impl<'info, T: Accounts<'info>> Accounts<'info> for Box { fn try_accounts( program_id: &Pubkey, accounts: &mut &[AccountInfo<'info>], ix_data: &[u8], bumps: &mut BTreeMap, ) -> Result { T::try_accounts(program_id, accounts, ix_data, bumps).map(Box::new) } } impl<'info, T: AccountsExit<'info>> AccountsExit<'info> for Box { fn exit(&self, program_id: &Pubkey) -> ProgramResult { T::exit(Deref::deref(self), program_id) } } impl<'info, T: ToAccountInfos<'info>> ToAccountInfos<'info> for Box { fn to_account_infos(&self) -> Vec> { T::to_account_infos(self) } } impl ToAccountMetas for Box { fn to_account_metas(&self, is_signer: Option) -> Vec { T::to_account_metas(self, is_signer) } } impl<'info, T: AccountsClose<'info>> AccountsClose<'info> for Box { fn close(&self, sol_destination: AccountInfo<'info>) -> ProgramResult { T::close(self, sol_destination) } }