pub struct VirtualState<const N: usize> { /* private fields */ }Expand description
A virtual state assembly mapping N slots to accounts.
Stack-allocated, const-generic. No heap, no alloc.
Implementations§
Source§impl<const N: usize> VirtualState<N>
impl<const N: usize> VirtualState<N>
Sourcepub const fn map(self, slot: usize, account_index: u8) -> Self
pub const fn map(self, slot: usize, account_index: u8) -> Self
Map a virtual slot to an account index (read-only owned).
Sourcepub const fn map_mut(self, slot: usize, account_index: u8) -> Self
pub const fn map_mut(self, slot: usize, account_index: u8) -> Self
Map a writable virtual slot.
Sourcepub const fn map_foreign(self, slot: usize, account_index: u8) -> Self
pub const fn map_foreign(self, slot: usize, account_index: u8) -> Self
Map a foreign (unowned) virtual slot.
Sourcepub const fn set_slot(self, slot: usize, vs: VirtualSlot) -> Self
pub const fn set_slot(self, slot: usize, vs: VirtualSlot) -> Self
Set a slot directly. Used by the hopper_virtual! macro for
custom slot configurations that don’t fit the standard map/map_mut/map_foreign
builder methods (e.g., writable but unowned).
Sourcepub const fn slot_count(&self) -> usize
pub const fn slot_count(&self) -> usize
Number of mapped slots (highest slot index + 1).
Sourcepub fn validate(
&self,
accounts: &[AccountView],
program_id: &Address,
) -> Result<(), ProgramError>
pub fn validate( &self, accounts: &[AccountView], program_id: &Address, ) -> Result<(), ProgramError>
Validate all slots against the instruction accounts.
Checks: account bounds, ownership, writability.
Sourcepub fn overlay<'a, T: Pod + FixedLayout>(
&self,
accounts: &'a [AccountView],
slot: usize,
) -> Result<Ref<'a, T>, ProgramError>
pub fn overlay<'a, T: Pod + FixedLayout>( &self, accounts: &'a [AccountView], slot: usize, ) -> Result<Ref<'a, T>, ProgramError>
Get a typed immutable overlay from a virtual slot.
Sourcepub fn overlay_mut<'a, T: Pod + FixedLayout>(
&self,
accounts: &'a [AccountView],
slot: usize,
) -> Result<RefMut<'a, T>, ProgramError>
pub fn overlay_mut<'a, T: Pod + FixedLayout>( &self, accounts: &'a [AccountView], slot: usize, ) -> Result<RefMut<'a, T>, ProgramError>
Get a typed mutable overlay from a virtual slot.
§Safety rationale for mut_from_ref
The &self receiver is sound because hopper-native’s AccountView uses
Solana runtime interior mutability (pointer-based access to account data).
The slot’s require_writable flag is checked to ensure we only mutate
accounts the runtime has granted write access to.
Sourcepub fn data<'a>(
&self,
accounts: &'a [AccountView],
slot: usize,
) -> Result<Ref<'a, [u8]>, ProgramError>
pub fn data<'a>( &self, accounts: &'a [AccountView], slot: usize, ) -> Result<Ref<'a, [u8]>, ProgramError>
Get raw immutable data from a virtual slot.
Sourcepub fn account<'a>(
&self,
accounts: &'a [AccountView],
slot: usize,
) -> Result<&'a AccountView, ProgramError>
pub fn account<'a>( &self, accounts: &'a [AccountView], slot: usize, ) -> Result<&'a AccountView, ProgramError>
Get the AccountView for a virtual slot.