Skip to main content

VirtualState

Struct VirtualState 

Source
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>

Source

pub const fn new() -> Self

Create a new empty virtual state.

Source

pub const fn map(self, slot: usize, account_index: u8) -> Self

Map a virtual slot to an account index (read-only owned).

Source

pub const fn map_mut(self, slot: usize, account_index: u8) -> Self

Map a writable virtual slot.

Source

pub const fn map_foreign(self, slot: usize, account_index: u8) -> Self

Map a foreign (unowned) virtual slot.

Source

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).

Source

pub const fn slot_count(&self) -> usize

Number of mapped slots (highest slot index + 1).

Source

pub fn validate( &self, accounts: &[AccountView], program_id: &Address, ) -> Result<(), ProgramError>

Validate all slots against the instruction accounts.

Checks: account bounds, ownership, writability.

Source

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.

Source

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.

Source

pub fn data<'a>( &self, accounts: &'a [AccountView], slot: usize, ) -> Result<Ref<'a, [u8]>, ProgramError>

Get raw immutable data from a virtual slot.

Source

pub fn account<'a>( &self, accounts: &'a [AccountView], slot: usize, ) -> Result<&'a AccountView, ProgramError>

Get the AccountView for a virtual slot.

Trait Implementations§

Source§

impl<const N: usize> Default for VirtualState<N>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<const N: usize> Freeze for VirtualState<N>

§

impl<const N: usize> RefUnwindSafe for VirtualState<N>

§

impl<const N: usize> Send for VirtualState<N>

§

impl<const N: usize> Sync for VirtualState<N>

§

impl<const N: usize> Unpin for VirtualState<N>

§

impl<const N: usize> UnsafeUnpin for VirtualState<N>

§

impl<const N: usize> UnwindSafe for VirtualState<N>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.