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§
Sourcefn get_tlv_data_mut(&mut self) -> &mut [u8] ⓘ
fn get_tlv_data_mut(&mut self) -> &mut [u8] ⓘ
Get the underlying TLV data as mutable
Sourcefn get_account_type_mut(&mut self) -> &mut [u8] ⓘ
fn get_account_type_mut(&mut self) -> &mut [u8] ⓘ
Get the underlying account type as mutable
Provided Methods§
Sourcefn get_extension_bytes_mut<V: Extension>(
&mut self,
) -> Result<&mut [u8], ProgramError>
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
Sourcefn get_extension_mut<V: Extension + Pod>(
&mut self,
) -> Result<&mut V, ProgramError>
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
Sourcefn pack_variable_len_extension<V: Extension + VariableLenPack>(
&mut self,
extension: &V,
) -> Result<(), ProgramError>
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
Sourcefn init_extension<V: Extension + Pod + Default>(
&mut self,
overwrite: bool,
) -> Result<&mut V, ProgramError>
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.
Sourcefn realloc_variable_len_extension<V: Extension + VariableLenPack>(
&mut self,
new_extension: &V,
) -> Result<(), ProgramError>
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.
Sourcefn realloc<V: Extension + VariableLenPack>(
&mut self,
length: usize,
) -> Result<&mut [u8], ProgramError>
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.
Sourcefn init_variable_len_extension<V: Extension + VariableLenPack>(
&mut self,
extension: &V,
overwrite: bool,
) -> Result<(), ProgramError>
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
Sourcefn alloc<V: Extension>(
&mut self,
length: usize,
overwrite: bool,
) -> Result<&mut [u8], ProgramError>
fn alloc<V: Extension>( &mut self, length: usize, overwrite: bool, ) -> Result<&mut [u8], ProgramError>
Allocate some space for the extension in the TLV data
Sourcefn init_account_extension_from_type(
&mut self,
extension_type: ExtensionType,
) -> Result<(), ProgramError>
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.
Sourcefn init_account_type(&mut self) -> Result<(), ProgramError>
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.
Sourcefn check_account_type_matches_extension_type(&self) -> Result<(), ProgramError>
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.