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
sourceimpl<'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 get_extension<V: Extension>(&self) -> Result<&V, ProgramError>
pub fn get_extension<V: Extension>(&self) -> Result<&V, ProgramError>
Unpack a portion of the TLV data as the desired 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.
sourcepub fn get_extension_types(&self) -> Result<Vec<ExtensionType>, ProgramError>
pub fn get_extension_types(&self) -> Result<Vec<ExtensionType>, ProgramError>
Iterates through the TLV entries, returning only the types