Skip to main content

VerifiedAccountMut

Struct VerifiedAccountMut 

Source
pub struct VerifiedAccountMut<'a, T: Pod + FixedLayout> { /* private fields */ }
Expand description

Mutable verified account – proof that validation passed, with write access.

Implementations§

Source§

impl<'a, T: Pod + FixedLayout> VerifiedAccountMut<'a, T>

Source

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

Construct from pre-validated mutable data.

Source

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

Construct from a Hopper mutable borrow guard.

Source

pub fn get(&self) -> &T

Get an immutable reference to the overlay.

The returned reference is bounded by &self; it cannot outlive this VerifiedAccountMut, which owns the mutable borrow guard or validated raw mutable slice.

Source

pub fn get_mut(&mut self) -> &mut T

Get a mutable reference to the overlay.

The returned reference is bounded by &mut self, so there can be only one mutable overlay at a time and it cannot outlive the wrapper that owns the underlying account borrow.

Source

pub fn with<U, F>(&self, f: F) -> U
where F: FnOnce(&T) -> U,

Run a closure with the verified whole-layout overlay.

Source

pub fn with_mut<U, F>(&mut self, f: F) -> U
where F: FnOnce(&mut T) -> U,

Run a closure with the verified mutable whole-layout overlay.

Source

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

Raw data (immutable).

Source

pub fn data_mut(&mut self) -> &mut [u8]

Raw data (mutable).

Source

pub fn map<U, F>(&self, f: F) -> U
where F: FnOnce(&T) -> U,

Project a field from the verified overlay (immutable).

Source

pub fn map_mut<U, F>(&mut self, f: F) -> U
where F: FnOnce(&mut T) -> U,

Project a field for mutation.

let mut vault = Vault::load_mut(account, program_id)?;
vault.map_mut(|v| {
    v.balance = WireU64::new(100);
});
Source

pub fn overlay_at<U: Pod + FixedLayout>( &self, offset: usize, ) -> Result<&U, ProgramError>

Overlay a second Pod type at a given offset (immutable).

Source

pub fn overlay_at_mut<U: Pod + FixedLayout>( &mut self, offset: usize, ) -> Result<&mut U, ProgramError>

Overlay a second Pod type at a given offset (mutable).

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

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

§

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

§

impl<'a, T> !UnwindSafe for VerifiedAccountMut<'a, T>

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.