Struct spl_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_bytes_mut<V: Extension>(
&mut self
) -> Result<&mut [u8], ProgramError>
pub fn get_extension_bytes_mut<V: Extension>( &mut self ) -> Result<&mut [u8], ProgramError>
Unpack a portion of the TLV data as the base mutable bytes
sourcepub fn get_extension_mut<V: Extension + Pod>(
&mut self
) -> Result<&mut V, ProgramError>
pub fn get_extension_mut<V: Extension + Pod>( &mut self ) -> Result<&mut V, ProgramError>
Unpack a portion of the TLV data as the desired type that allows modifying the type
sourcepub fn pack_variable_len_extension<V: Extension + VariableLenPack>(
&mut self,
extension: &V
) -> Result<(), ProgramError>
pub fn pack_variable_len_extension<V: Extension + VariableLenPack>( &mut self, extension: &V ) -> Result<(), ProgramError>
Packs a variable-length extension into its appropriate data segment. Fails if space hasn’t already been allocated for the given extension
sourcepub fn init_extension<V: Extension + Pod + Default>(
&mut self,
overwrite: bool
) -> Result<&mut V, ProgramError>
pub fn init_extension<V: Extension + Pod + Default>( &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 realloc_variable_len_extension<V: Extension + VariableLenPack>(
&mut self,
new_extension: &V
) -> Result<(), ProgramError>
pub fn realloc_variable_len_extension<V: Extension + VariableLenPack>( &mut self, new_extension: &V ) -> Result<(), ProgramError>
Reallocate and overwite the TLV entry for the given variable-length extension.
Returns an error if the extension is not present, or if there is not enough space in the buffer.
sourcepub fn init_variable_len_extension<V: Extension + VariableLenPack>(
&mut self,
extension: &V,
overwrite: bool
) -> Result<(), ProgramError>
pub fn init_variable_len_extension<V: Extension + VariableLenPack>( &mut self, extension: &V, overwrite: bool ) -> Result<(), ProgramError>
Allocate the given number of bytes for the given variable-length extension and write its contents into the TLV buffer.
This can only be used for variable-sized types, such as String
or
Vec
. Pod
types must use init_extension
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_bytes<V: Extension>(&self) -> Result<&[u8], ProgramError>
fn get_extension_bytes<V: Extension>(&self) -> Result<&[u8], ProgramError>
source§fn get_extension<V: Extension + Pod>(&self) -> Result<&V, ProgramError>
fn get_extension<V: Extension + Pod>(&self) -> Result<&V, ProgramError>
source§fn get_variable_len_extension<V: Extension + VariableLenPack>(
&self
) -> Result<V, ProgramError>
fn get_variable_len_extension<V: Extension + VariableLenPack>( &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§fn try_get_account_len(&self) -> Result<usize, ProgramError>
fn try_get_account_len(&self) -> Result<usize, ProgramError>
source§fn try_get_new_account_len<V: Extension + Pod>(
&self
) -> Result<usize, ProgramError>
fn try_get_new_account_len<V: Extension + Pod>( &self ) -> Result<usize, ProgramError>
source§fn try_get_new_account_len_for_variable_len_extension<V: Extension + VariableLenPack>(
&self,
new_extension: &V
) -> Result<usize, ProgramError>
fn try_get_new_account_len_for_variable_len_extension<V: Extension + VariableLenPack>( &self, new_extension: &V ) -> Result<usize, ProgramError>
source§impl<'data, S: PartialEq + BaseState> PartialEq for StateWithExtensionsMut<'data, S>
impl<'data, S: PartialEq + BaseState> PartialEq 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 ==
.