pub struct HopperAccount<'a, T>{ /* private fields */ }Expand description
A layout-bound, owner-validated account.
Wraps a hopper-native AccountView with layout type information.
Access the typed data via read() for immutable or write() for mutable.
Validation is performed at construction time:
- Owner matches program_id
- Discriminator, version, layout_id match T’s constants
- Account data size matches T’s expected layout size
Implementations§
Source§impl<'a, T> HopperAccount<'a, T>
impl<'a, T> HopperAccount<'a, T>
Sourcepub fn from_account(
account: &'a AccountView,
program_id: &'a Address,
) -> Result<HopperAccount<'a, T>, ProgramError>
pub fn from_account( account: &'a AccountView, program_id: &'a Address, ) -> Result<HopperAccount<'a, T>, ProgramError>
Construct from an AccountView with full header validation.
Validates: owner == program_id, discriminator, version, layout_id, size.
Sourcepub fn from_account_mut(
account: &'a AccountView,
program_id: &'a Address,
) -> Result<HopperAccount<'a, T>, ProgramError>
pub fn from_account_mut( account: &'a AccountView, program_id: &'a Address, ) -> Result<HopperAccount<'a, T>, ProgramError>
Construct from an AccountView that must also be writable.
Sourcepub fn read(&self) -> Result<VerifiedAccount<'a, T>, ProgramError>
pub fn read(&self) -> Result<VerifiedAccount<'a, T>, ProgramError>
Read the typed layout overlay (immutable).
Returns a reference to the typed layout struct overlaid on account data.
§Safety
The caller must ensure no conflicting mutable borrows exist on this account’s data. Frame-level borrow tracking handles this in normal usage.
Sourcepub fn write(&self) -> Result<VerifiedAccountMut<'a, T>, ProgramError>
pub fn write(&self) -> Result<VerifiedAccountMut<'a, T>, ProgramError>
Write to the typed layout overlay (mutable).
Returns a mutable reference to the typed layout struct.
The account must have been constructed via from_account_mut or
the caller must ensure writability.
§Safety
The caller must ensure exclusive access to this account’s data.
Sourcepub fn to_account_view(&self) -> &'a AccountView
pub fn to_account_view(&self) -> &'a AccountView
The underlying AccountView.