#[repr(C)]pub struct AccountInfo { /* private fields */ }
Expand description
Wrapper struct for an Account
.
This struct provides safe access to the data in an Account
. It is also
used to track borrows of the account data and lamports, given that an
account can be “shared” across multiple AccountInfo
instances.
Implementations§
Source§impl AccountInfo
impl AccountInfo
Sourcepub fn is_writable(&self) -> bool
pub fn is_writable(&self) -> bool
Indicates whether the account is writable.
Sourcepub fn executable(&self) -> bool
pub fn executable(&self) -> bool
Indicates whether this account represents a program.
Program accounts are always read-only.
Sourcepub fn data_is_empty(&self) -> bool
pub fn data_is_empty(&self) -> bool
Indicates whether the account data is empty.
An account is considered empty if the data length is zero.
Sourcepub unsafe fn unchecked_borrow_lamports(&self) -> &u64
pub unsafe fn unchecked_borrow_lamports(&self) -> &u64
Returns a read-only reference to the lamports in the account.
§SAFETY
This does not check or modify the 4-bit refcell. Useful when instruction has verified non-duplicate accounts.
Sourcepub unsafe fn unchecked_borrow_mut_lamports(&self) -> &mut u64
pub unsafe fn unchecked_borrow_mut_lamports(&self) -> &mut u64
Returns a mutable reference to the lamports in the account.
§SAFETY
This does not check or modify the 4-bit refcell. Useful when instruction has verified non-duplicate accounts.
Sourcepub unsafe fn unchecked_borrow_data(&self) -> &[u8] ⓘ
pub unsafe fn unchecked_borrow_data(&self) -> &[u8] ⓘ
Returns a read-only reference to the data in the account.
§SAFETY
This does not check or modify the 4-bit refcell. Useful when instruction has verified non-duplicate accounts.
Sourcepub unsafe fn unchecked_borrow_mut_data(&self) -> &mut [u8] ⓘ
pub unsafe fn unchecked_borrow_mut_data(&self) -> &mut [u8] ⓘ
Returns a mutable reference to the data in the account.
§SAFETY
This does not check or modify the 4-bit refcell. Useful when instruction has verified non-duplicate accounts.
Sourcepub fn try_borrow_lamports(&self) -> Result<Ref<'_, u64>, ProgramError>
pub fn try_borrow_lamports(&self) -> Result<Ref<'_, u64>, ProgramError>
Tries to get a read-only reference to the lamport field, failing if the field is already mutable borrowed or if 7 borrows already exist.
Sourcepub fn try_borrow_mut_lamports(&self) -> Result<RefMut<'_, u64>, ProgramError>
pub fn try_borrow_mut_lamports(&self) -> Result<RefMut<'_, u64>, ProgramError>
Tries to get a read only reference to the lamport field, failing if the field is already borrowed in any form.
Sourcepub fn try_borrow_data(&self) -> Result<Ref<'_, [u8]>, ProgramError>
pub fn try_borrow_data(&self) -> Result<Ref<'_, [u8]>, ProgramError>
Tries to get a read only reference to the data field, failing if the field is already mutable borrowed or if 7 borrows already exist.
Sourcepub fn try_borrow_mut_data(&self) -> Result<RefMut<'_, [u8]>, ProgramError>
pub fn try_borrow_mut_data(&self) -> Result<RefMut<'_, [u8]>, ProgramError>
Tries to get a read only reference to the data field, failing if the field is already borrowed in any form.
Sourcepub fn realloc(
&self,
new_len: usize,
zero_init: bool,
) -> Result<(), ProgramError>
pub fn realloc( &self, new_len: usize, zero_init: bool, ) -> Result<(), ProgramError>
Realloc the account’s data and optionally zero-initialize the new memory.
Note: Account data can be increased within a single call by up to
solana_program::entrypoint::MAX_PERMITTED_DATA_INCREASE
bytes.
Note: Memory used to grow is already zero-initialized upon program
entrypoint and re-zeroing it wastes compute units. If within the same
call a program reallocs from larger to smaller and back to larger again
the new space could contain stale data. Pass true
for zero_init
in
this case, otherwise compute units will be wasted re-zero-initializing.
§Safety
This method makes assumptions about the layout and location of memory
referenced by AccountInfo
fields. It should only be called for
instances of AccountInfo
that were created by the runtime and received
in the process_instruction
entrypoint of a program.
Trait Implementations§
Source§impl Clone for AccountInfo
impl Clone for AccountInfo
Source§fn clone(&self) -> AccountInfo
fn clone(&self) -> AccountInfo
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl From<&AccountInfo> for CAccountInfo
impl From<&AccountInfo> for CAccountInfo
Source§fn from(account: &AccountInfo) -> Self
fn from(account: &AccountInfo) -> Self
Source§impl From<&AccountInfo> for CAccountMeta
impl From<&AccountInfo> for CAccountMeta
Source§fn from(account: &AccountInfo) -> Self
fn from(account: &AccountInfo) -> Self
Source§impl PartialEq for AccountInfo
impl PartialEq for AccountInfo
impl Eq for AccountInfo
impl StructuralPartialEq for AccountInfo
Auto Trait Implementations§
impl Freeze for AccountInfo
impl RefUnwindSafe for AccountInfo
impl !Send for AccountInfo
impl !Sync for AccountInfo
impl Unpin for AccountInfo
impl UnwindSafe for AccountInfo
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more