pub struct VariableBytes<const RECOMMENDED_ALLOCATION: u32> { /* private fields */ }
Expand description
Container for storing variable number of bytes.
RECOMMENDED_ALLOCATION
is what is being used when a host needs to allocate memory for call
into guest, but guest may receive an allocation with more or less memory in practice depending
on other circumstances, like when called from another contract with specific allocation
specified.
Implementations§
Source§impl<const RECOMMENDED_ALLOCATION: u32> VariableBytes<RECOMMENDED_ALLOCATION>
impl<const RECOMMENDED_ALLOCATION: u32> VariableBytes<RECOMMENDED_ALLOCATION>
Sourcepub fn from_buffer<'a>(
buffer: &'a [<Self as IoType>::PointerType],
size: &'a u32,
) -> impl Deref<Target = Self> + 'a
pub fn from_buffer<'a>( buffer: &'a [<Self as IoType>::PointerType], size: &'a u32, ) -> impl Deref<Target = Self> + 'a
Sourcepub fn from_buffer_mut<'a>(
buffer: &'a mut [<Self as IoType>::PointerType],
size: &'a mut u32,
) -> impl DerefMut<Target = Self> + 'a
pub fn from_buffer_mut<'a>( buffer: &'a mut [<Self as IoType>::PointerType], size: &'a mut u32, ) -> impl DerefMut<Target = Self> + 'a
Sourcepub fn from_uninit<'a, const CAPACITY: usize>(
uninit: &'a mut MaybeUninit<[<Self as IoType>::PointerType; CAPACITY]>,
size: &'a mut u32,
) -> impl Deref<Target = Self> + 'a
pub fn from_uninit<'a, const CAPACITY: usize>( uninit: &'a mut MaybeUninit<[<Self as IoType>::PointerType; CAPACITY]>, size: &'a mut u32, ) -> impl Deref<Target = Self> + 'a
pub fn size(&self) -> u32
pub fn capacity(&self) -> u32
Sourcepub fn get_initialized(&self) -> &[u8]
pub fn get_initialized(&self) -> &[u8]
Try to get access to initialized bytes
Sourcepub fn get_initialized_mut(&mut self) -> &mut [u8]
pub fn get_initialized_mut(&mut self) -> &mut [u8]
Try to get exclusive access to initialized Data
, returns None
if not initialized
Sourcepub fn append(&mut self, bytes: &[u8]) -> bool
pub fn append(&mut self, bytes: &[u8]) -> bool
Append some bytes by using more of allocated, but currently unused bytes.
true
is returned on success, but if there isn’t enough unused bytes left, false
is.
Sourcepub fn truncate(&mut self, new_size: u32) -> bool
pub fn truncate(&mut self, new_size: u32) -> bool
Truncate internal initialized bytes to this size.
Returns true
on success or false
if new_size
is larger than
Self::size()
.
Sourcepub fn copy_from(&mut self, src: &Self) -> bool
pub fn copy_from(&mut self, src: &Self) -> bool
Copy contents from another instance.
Returns false
if actual capacity of the instance is not enough to copy contents of src
Sourcepub fn as_mut_ptr(&mut self) -> &mut NonNull<u8>
pub fn as_mut_ptr(&mut self) -> &mut NonNull<u8>
Get exclusive access to underlying pointer with no checks.
Can be used for initialization with Self::assume_init()
called afterward to confirm how
many bytes are in use right now.
Trait Implementations§
Source§impl<const RECOMMENDED_ALLOCATION: u32> IoType for VariableBytes<RECOMMENDED_ALLOCATION>
impl<const RECOMMENDED_ALLOCATION: u32> IoType for VariableBytes<RECOMMENDED_ALLOCATION>
Source§const METADATA: &[u8]
const METADATA: &[u8]
IoTypeMetadataKind
for encoding detailsSource§type PointerType = u8
type PointerType = u8
IoType
represents