spl_token_2022::extension

Trait BaseStateWithExtensionsMut

Source
pub trait BaseStateWithExtensionsMut<S: BaseState>: BaseStateWithExtensions<S> {
Show 13 methods // Required methods fn get_tlv_data_mut(&mut self) -> &mut [u8] ; fn get_account_type_mut(&mut self) -> &mut [u8] ; // Provided methods fn get_extension_bytes_mut<V: Extension>( &mut self, ) -> Result<&mut [u8], ProgramError> { ... } fn get_extension_mut<V: Extension + Pod>( &mut self, ) -> Result<&mut V, ProgramError> { ... } fn pack_variable_len_extension<V: Extension + VariableLenPack>( &mut self, extension: &V, ) -> Result<(), ProgramError> { ... } fn init_extension<V: Extension + Pod + Default>( &mut self, overwrite: bool, ) -> Result<&mut V, ProgramError> { ... } fn realloc_variable_len_extension<V: Extension + VariableLenPack>( &mut self, new_extension: &V, ) -> Result<(), ProgramError> { ... } fn realloc<V: Extension + VariableLenPack>( &mut self, length: usize, ) -> Result<&mut [u8], ProgramError> { ... } fn init_variable_len_extension<V: Extension + VariableLenPack>( &mut self, extension: &V, overwrite: bool, ) -> Result<(), ProgramError> { ... } fn alloc<V: Extension>( &mut self, length: usize, overwrite: bool, ) -> Result<&mut [u8], ProgramError> { ... } fn init_account_extension_from_type( &mut self, extension_type: ExtensionType, ) -> Result<(), ProgramError> { ... } fn init_account_type(&mut self) -> Result<(), ProgramError> { ... } fn check_account_type_matches_extension_type( &self, ) -> Result<(), ProgramError> { ... }
}
Expand description

Trait for mutable base state with extension

Required Methods§

Source

fn get_tlv_data_mut(&mut self) -> &mut [u8]

Get the underlying TLV data as mutable

Source

fn get_account_type_mut(&mut self) -> &mut [u8]

Get the underlying account type as mutable

Provided Methods§

Source

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

Source

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

Source

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

Source

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.

Source

fn realloc_variable_len_extension<V: Extension + VariableLenPack>( &mut self, new_extension: &V, ) -> Result<(), ProgramError>

Reallocate and overwrite 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.

Source

fn realloc<V: Extension + VariableLenPack>( &mut self, length: usize, ) -> Result<&mut [u8], ProgramError>

Reallocate the TLV entry for the given extension to the given number of bytes.

If the new length is smaller, it will compact the rest of the buffer and zero out the difference at the end. If it’s larger, it will move the rest of the buffer data and zero out the new data.

Returns an error if the extension is not present, or if this is not enough space in the buffer.

Source

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

Source

fn alloc<V: Extension>( &mut self, length: usize, overwrite: bool, ) -> Result<&mut [u8], ProgramError>

Allocate some space for the extension in the TLV data

Source

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.

Source

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.

Source

fn check_account_type_matches_extension_type(&self) -> Result<(), ProgramError>

Check that the account type on the account (if initialized) matches the account type for any extensions initialized on the TLV data

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§