#[repr(C)]pub struct VariableBytes<const RECOMMENDED_ALLOCATION: u32 = 0> { /* 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 const fn from_buffer<'a>(
buffer: &'a [<Self as IoType>::PointerType],
size: &'a u32,
) -> impl Deref<Target = Self> + 'a
pub const 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 DerefMut<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 DerefMut<Target = Self> + 'a
pub const fn size(&self) -> u32
Sourcepub const fn get_initialized(&self) -> &[u8]
pub const 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<T>(&mut self, src: &T) -> boolwhere
T: IoType,
pub fn copy_from<T>(&mut self, src: &T) -> boolwhere
T: IoType,
Copy contents from another IoType
.
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 the 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.
Sourcepub fn cast_ref<const DIFFERENT_RECOMMENDED_ALLOCATION: u32>(
&self,
) -> &VariableBytes<DIFFERENT_RECOMMENDED_ALLOCATION>
pub fn cast_ref<const DIFFERENT_RECOMMENDED_ALLOCATION: u32>( &self, ) -> &VariableBytes<DIFFERENT_RECOMMENDED_ALLOCATION>
Cast a shared reference to this instance into a reference to an instance of a different recommended allocation
Sourcepub fn cast_mut<const DIFFERENT_RECOMMENDED_ALLOCATION: u32>(
&mut self,
) -> &mut VariableBytes<DIFFERENT_RECOMMENDED_ALLOCATION>
pub fn cast_mut<const DIFFERENT_RECOMMENDED_ALLOCATION: u32>( &mut self, ) -> &mut VariableBytes<DIFFERENT_RECOMMENDED_ALLOCATION>
Cast an exclusive reference to this instance into a reference to an instance of a different recommended allocation
Sourcepub fn read_trivial_type<T>(&self) -> Option<T>where
T: TrivialType,
pub fn read_trivial_type<T>(&self) -> Option<T>where
T: TrivialType,
Reads and returns value of type T
or None
if there is not enough data.
Checks alignment internally to support both aligned and unaligned reads.
Trait Implementations§
Source§impl<const RECOMMENDED_ALLOCATION: u32> Debug for VariableBytes<RECOMMENDED_ALLOCATION>
impl<const RECOMMENDED_ALLOCATION: u32> Debug for VariableBytes<RECOMMENDED_ALLOCATION>
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