Skip to main content

VerifiedAccount

Struct VerifiedAccount 

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

Source

pub fn new(data: &'a [u8]) -> Result<Self, ProgramError>

Construct from pre-validated data.

Only tiered loading functions should create these.

Source

pub fn from_ref(data: Ref<'a, [u8]>) -> Result<Self, ProgramError>

Construct from a Hopper borrow guard.

Source

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.

Source

pub fn with<U, F>(&self, f: F) -> U
where F: FnOnce(&T) -> 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.

Source

pub fn data(&self) -> &[u8]

Raw data.

Source

pub fn body(&self) -> &[u8]

Body data after header.

Source

pub fn map<U, F>(&self, f: F) -> U
where F: FnOnce(&T) -> 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);
Source

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.

Source

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.

Auto Trait Implementations§

§

impl<'a, T> Freeze for VerifiedAccount<'a, T>

§

impl<'a, T> RefUnwindSafe for VerifiedAccount<'a, T>
where T: RefUnwindSafe,

§

impl<'a, T> !Send for VerifiedAccount<'a, T>

§

impl<'a, T> !Sync for VerifiedAccount<'a, T>

§

impl<'a, T> Unpin for VerifiedAccount<'a, T>
where T: Unpin,

§

impl<'a, T> UnsafeUnpin for VerifiedAccount<'a, T>

§

impl<'a, T> UnwindSafe for VerifiedAccount<'a, T>
where T: UnwindSafe,

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.