Struct safe_token_2022::extension::StateWithExtensionsMut
source · pub struct StateWithExtensionsMut<'data, S: BaseState> {
pub base: S,
/* private fields */
}
Expand description
Encapsulates mutable base state data (mint or account) with possible extensions
Fields§
§base: S
Unpacked base data
Implementations§
source§impl<'data, S: BaseState> StateWithExtensionsMut<'data, S>
impl<'data, S: BaseState> StateWithExtensionsMut<'data, S>
sourcepub fn unpack(input: &'data mut [u8]) -> Result<Self, ProgramError>
pub fn unpack(input: &'data mut [u8]) -> Result<Self, ProgramError>
Unpack base state, leaving the extension data as a mutable slice
Fails if the base state is not initialized.
sourcepub fn unpack_uninitialized(
input: &'data mut [u8]
) -> Result<Self, ProgramError>
pub fn unpack_uninitialized( input: &'data mut [u8] ) -> Result<Self, ProgramError>
Unpack an uninitialized base state, leaving the extension data as a mutable slice
Fails if the base state has already been initialized.
sourcepub fn get_extension_mut<V: Extension>(
&mut self
) -> Result<&mut V, ProgramError>
pub fn get_extension_mut<V: Extension>( &mut self ) -> Result<&mut V, ProgramError>
Unpack a portion of the TLV data as the desired type that allows modifying the type
sourcepub fn init_extension<V: Extension>(
&mut self,
overwrite: bool
) -> Result<&mut V, ProgramError>
pub fn init_extension<V: Extension>( &mut self, overwrite: bool ) -> Result<&mut V, ProgramError>
Packs the default extension data into an open slot if not already found in the
data buffer. If extension is already found in the buffer, it overwrites the existing
extension with the default state if overwrite
is set. If extension found, but
overwrite
is not set, it returns error.
sourcepub fn init_account_extension_from_type(
&mut self,
extension_type: ExtensionType
) -> Result<(), ProgramError>
pub fn init_account_extension_from_type( &mut self, extension_type: ExtensionType ) -> Result<(), ProgramError>
If extension_type
is an Account-associated ExtensionType that requires initialization on
InitializeAccount, this method packs the default relevant Extension of an ExtensionType
into an open slot if not already found in the data buffer, otherwise overwrites the
existing extension with the default state. For all other ExtensionTypes, this is a no-op.
sourcepub fn init_account_type(&mut self) -> Result<(), ProgramError>
pub fn init_account_type(&mut self) -> Result<(), ProgramError>
Write the account type into the buffer, done during the base state initialization Noops if there is no room for an extension in the account, needed for pure base mints / accounts.
Trait Implementations§
source§impl<'a, S: BaseState> BaseStateWithExtensions<S> for StateWithExtensionsMut<'a, S>
impl<'a, S: BaseState> BaseStateWithExtensions<S> for StateWithExtensionsMut<'a, S>
source§fn get_tlv_data(&self) -> &[u8] ⓘ
fn get_tlv_data(&self) -> &[u8] ⓘ
source§fn get_extension<V: Extension>(&self) -> Result<&V, ProgramError>
fn get_extension<V: Extension>(&self) -> Result<&V, ProgramError>
source§fn get_extension_types(&self) -> Result<Vec<ExtensionType>, ProgramError>
fn get_extension_types(&self) -> Result<Vec<ExtensionType>, ProgramError>
source§fn get_first_extension_type(
&self
) -> Result<Option<ExtensionType>, ProgramError>
fn get_first_extension_type( &self ) -> Result<Option<ExtensionType>, ProgramError>
source§impl<'data, S: PartialEq + BaseState> PartialEq<StateWithExtensionsMut<'data, S>> for StateWithExtensionsMut<'data, S>
impl<'data, S: PartialEq + BaseState> PartialEq<StateWithExtensionsMut<'data, S>> for StateWithExtensionsMut<'data, S>
source§fn eq(&self, other: &StateWithExtensionsMut<'data, S>) -> bool
fn eq(&self, other: &StateWithExtensionsMut<'data, S>) -> bool
self
and other
values to be equal, and is used
by ==
.