Skip to main content

BorrowedAccount

Struct BorrowedAccount 

Source
pub struct BorrowedAccount { /* private fields */ }
Expand description

Borrowed zero-copy account view into an aligned external buffer.

Implementations§

Source§

impl BorrowedAccount

Source

pub unsafe fn span(ptr: NonNull<StorageUnit>) -> u32

Returns the total borrowed span in StorageUnits.

§Safety

ptr must point to a valid borrowed buffer created by OwnedAccount::serialize.

Source

pub unsafe fn pubkey(ptr: NonNull<StorageUnit>) -> Pubkey

Reads the account’s pubkey stored in the image prefix.

§Safety

ptr must point to a valid borrowed buffer created by OwnedAccount::serialize.

Source

pub unsafe fn init(buffer: NonNull<StorageUnit>) -> Self

Builds a borrowed account view from an aligned account buffer.

§Safety

buffer must be 8-byte aligned and point to a valid borrowed account buffer whose first bytes are the account header, followed by two image-sized payloads. The active image is selected from the header sequence parity.

Source

pub unsafe fn translate(&mut self)

Copies the active image into the shadow image and switches to it.

§Safety

The borrowed image must still be the one selected by init.

Source

pub fn commit(&self)

Publishes the shadow image if it was prepared against the current sequence.

Source

pub unsafe fn reset(&mut self)

Repoints this view to the currently active image without copying data.

§Safety

The header must remain live, and self must be a view previously produced by Self::init or Self::translate for that borrowed buffer.

Source

pub unsafe fn rollback(&self)

Undoes the latest commit, by adjusting the sequence counter

§Safety

Call this only after commit to avoid data corruption;

Source

pub fn owner(&self) -> Pubkey

Returns the owner pubkey from the active image.

Source

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

Returns the serialized active image bytes that define account state.

The slice starts at AccountCore, includes the DataHeader, and stops after initialized data. It excludes the shared header, pubkey prefix, inactive shadow image, and spare data capacity.

Trait Implementations§

Source§

impl Eq for BorrowedAccount

Source§

impl From<&BorrowedAccount> for OwnedAccount

Source§

fn from(value: &BorrowedAccount) -> Self

Converts to this type from the input type.
Source§

impl From<BorrowedAccount> for AccountSharedData

Wraps a borrowed account in AccountSharedData.

Source§

fn from(value: BorrowedAccount) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for BorrowedAccount

Source§

fn eq(&self, other: &BorrowedAccount) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Send for BorrowedAccount

Source§

impl StructuralPartialEq for BorrowedAccount

Auto Trait Implementations§

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.