pub struct VerifiedAccount<'a, T: Pod + FixedLayout> { /* private fields */ }Expand description
Immutable verified account – proof that validation passed.
Implementations§
Source§impl<'a, T: Pod + FixedLayout> VerifiedAccount<'a, T>
impl<'a, T: Pod + FixedLayout> VerifiedAccount<'a, T>
Sourcepub fn new(data: &'a [u8]) -> Result<Self, ProgramError>
pub fn new(data: &'a [u8]) -> Result<Self, ProgramError>
Construct from pre-validated data.
Only tiered loading functions should create these.
Sourcepub fn from_ref(data: Ref<'a, [u8]>) -> Result<Self, ProgramError>
pub fn from_ref(data: Ref<'a, [u8]>) -> Result<Self, ProgramError>
Construct from a Hopper borrow guard.
Sourcepub fn get(&self) -> &T
pub fn get(&self) -> &T
Get an immutable reference to the overlay. Infallible after construction.
The returned reference is bounded by &self; it cannot outlive this
VerifiedAccount, which owns the borrow guard or validated raw slice
proving the overlay is safe to read.
Sourcepub fn with<U, F>(&self, f: F) -> U
pub fn with<U, F>(&self, f: F) -> U
Run a closure with the verified whole-layout overlay.
This is equivalent to f(self.get()), but makes the guard-scoped
lifetime obvious at call sites.
Sourcepub fn map<U, F>(&self, f: F) -> U
pub fn map<U, F>(&self, f: F) -> U
Project a field from the verified overlay.
The closure receives the typed overlay and returns a reference into it. The returned reference carries the lifetime of the verified data, preserving proof-of-validation provenance.
let vault = Vault::load(account, program_id)?;
let authority: &[u8; 32] = vault.map(|v| &v.authority);
let balance: &WireU64 = vault.map(|v| &v.balance);Sourcepub fn slice(&self, offset: usize, len: usize) -> Result<&[u8], ProgramError>
pub fn slice(&self, offset: usize, len: usize) -> Result<&[u8], ProgramError>
Project a byte sub-slice from the verified data.
Returns a sub-slice of the already-validated data at the given offset and length. Useful for accessing raw segments or embedded sub-structures without re-validation.
Sourcepub fn overlay_at<U: Pod + FixedLayout>(
&self,
offset: usize,
) -> Result<&U, ProgramError>
pub fn overlay_at<U: Pod + FixedLayout>( &self, offset: usize, ) -> Result<&U, ProgramError>
Overlay a second Pod type at a given offset within verified data.
Useful for accessing embedded sub-layouts in segmented accounts where the outer account has already been validated.