ab_contracts_io_type::variable_bytes

Struct VariableBytes

Source
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>

Source

pub fn from_buffer<'a>( buffer: &'a [<Self as IoType>::PointerType], size: &'a u32, ) -> impl Deref<Target = Self> + 'a

Create a new shared instance from provided memory buffer.

§Panics

Panics if size != buffer.len()

Source

pub fn from_buffer_mut<'a>( buffer: &'a mut [<Self as IoType>::PointerType], size: &'a mut u32, ) -> impl DerefMut<Target = Self> + 'a

Create a new exclusive instance from provided memory buffer.

§Panics

Panics if buffer.len() != size

Source

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

Create a new shared instance from provided memory buffer.

§Panics

Panics if size > CAPACITY

Source

pub fn size(&self) -> u32

Source

pub fn capacity(&self) -> u32

Source

pub fn get_initialized(&self) -> &[u8]

Try to get access to initialized bytes

Source

pub fn get_initialized_mut(&mut self) -> &mut [u8]

Try to get exclusive access to initialized Data, returns None if not initialized

Source

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.

Source

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().

Source

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

Source

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.

Source

pub unsafe fn assume_init(&mut self, size: u32) -> Option<&mut [u8]>

Assume that the first size are initialized and can be read.

Returns Some(initialized_bytes) on success or None if size is larger than its capacity.

§Safety

Caller must ensure size are actually initialized

Trait Implementations§

Source§

impl<const RECOMMENDED_ALLOCATION: u32> IoType for VariableBytes<RECOMMENDED_ALLOCATION>

Source§

const METADATA: &[u8]

Data structure metadata in binary form, describing shape and types of the contents, see IoTypeMetadataKind for encoding details
Source§

type PointerType = u8

Pointer with trivial type that this IoType represents
Source§

fn size(&self) -> u32

Number of bytes that are currently used to store data
Source§

unsafe fn size_ptr(&self) -> impl Deref<Target = NonNull<u32>>

Pointer to the number of bytes that are currently used to store data. Read more
Source§

unsafe fn size_mut_ptr(&mut self) -> impl DerefMut<Target = *mut u32>

An exclusive pointer to the number of bytes that are currently used to store data. Read more
Source§

fn capacity(&self) -> u32

Number of bytes are allocated right now
Source§

unsafe fn capacity_ptr(&self) -> impl Deref<Target = NonNull<u32>>

Number of bytes are allocated right now Read more
Source§

unsafe fn set_size(&mut self, size: u32)

Set the number of used bytes Read more
Source§

unsafe fn from_ptr<'a>( ptr: &'a NonNull<Self::PointerType>, size: &'a u32, capacity: u32, ) -> impl Deref<Target = Self> + 'a

Create a reference to a type, which is represented by provided memory. Read more
Source§

unsafe fn from_mut_ptr<'a>( ptr: &'a mut NonNull<Self::PointerType>, size: &'a mut *mut u32, capacity: u32, ) -> impl DerefMut<Target = Self> + 'a

Create a mutable reference to a type, which is represented by provided memory. Read more
Source§

unsafe fn as_ptr(&self) -> impl Deref<Target = NonNull<Self::PointerType>>

Get a raw pointer to the underlying data with no checks. Read more
Source§

unsafe fn as_mut_ptr( &mut self, ) -> impl DerefMut<Target = NonNull<Self::PointerType>>

Get an exclusive raw pointer to the underlying data with no checks. Read more
Source§

impl<const RECOMMENDED_ALLOCATION: u32> IoTypeOptional for VariableBytes<RECOMMENDED_ALLOCATION>

Auto Trait Implementations§

§

impl<const RECOMMENDED_ALLOCATION: u32> Freeze for VariableBytes<RECOMMENDED_ALLOCATION>

§

impl<const RECOMMENDED_ALLOCATION: u32> RefUnwindSafe for VariableBytes<RECOMMENDED_ALLOCATION>

§

impl<const RECOMMENDED_ALLOCATION: u32> !Send for VariableBytes<RECOMMENDED_ALLOCATION>

§

impl<const RECOMMENDED_ALLOCATION: u32> !Sync for VariableBytes<RECOMMENDED_ALLOCATION>

§

impl<const RECOMMENDED_ALLOCATION: u32> Unpin for VariableBytes<RECOMMENDED_ALLOCATION>

§

impl<const RECOMMENDED_ALLOCATION: u32> UnwindSafe for VariableBytes<RECOMMENDED_ALLOCATION>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.