Struct wasmtime::component::WasmList

source ·
pub struct WasmList<T> { /* private fields */ }
Expand description

Representation of a list of values that are owned by a WebAssembly instance.

For some more commentary about the rationale for this type see the documentation of WasmStr. In summary this type can avoid a copy when passing data to the host in some situations but is additionally more cumbersome to use by requiring a Store to be provided.

This type is used whenever a (list T) is returned from a TypedFunc, for example. This type represents a list of values that are stored in linear memory which are waiting to be read.

Note that this type represents only a valid range of bytes for the list itself, it does not represent validity of the elements themselves and that’s performed when they’re iterated.

Note that this type does not implement the Lower trait, only Lift.

Implementations§

source§

impl<T: Lift> WasmList<T>

source

pub fn len(&self) -> usize

Returns the item length of this vector

source

pub fn get(&self, store: impl AsContextMut, index: usize) -> Option<Result<T>>

Gets the nth element of this list.

Returns None if index is out of bounds. Returns Some(Err(..)) if the value couldn’t be decoded (it was invalid). Returns Some(Ok(..)) if the value is valid.

§Panics

This function will panic if the string did not originally come from the store specified.

source

pub fn iter<'a, U: 'a>( &'a self, store: impl Into<StoreContextMut<'a, U>>, ) -> impl ExactSizeIterator<Item = Result<T>> + 'a

Returns an iterator over the elements of this list.

Each item of the list may fail to decode and is represented through the Result value of the iterator.

source§

impl WasmList<i8>

source

pub fn as_le_slice<'a, T: 'a>( &self, store: impl Into<StoreContext<'a, T>>, ) -> &'a [i8]

Get access to the raw underlying memory for this list.

This method will return a direct slice into the original wasm module’s linear memory where the data for this slice is stored. This allows the embedder to have efficient access to the underlying memory if needed and avoid copies and such if desired.

Note that multi-byte integers are stored in little-endian format so portable processing of this slice must be aware of the host’s byte-endianness. The from_le constructors in the Rust standard library should be suitable for converting from little-endian.

§Panics

Panics if the store provided is not the one from which this slice originated.

source§

impl WasmList<i16>

source

pub fn as_le_slice<'a, T: 'a>( &self, store: impl Into<StoreContext<'a, T>>, ) -> &'a [i16]

Get access to the raw underlying memory for this list.

This method will return a direct slice into the original wasm module’s linear memory where the data for this slice is stored. This allows the embedder to have efficient access to the underlying memory if needed and avoid copies and such if desired.

Note that multi-byte integers are stored in little-endian format so portable processing of this slice must be aware of the host’s byte-endianness. The from_le constructors in the Rust standard library should be suitable for converting from little-endian.

§Panics

Panics if the store provided is not the one from which this slice originated.

source§

impl WasmList<i32>

source

pub fn as_le_slice<'a, T: 'a>( &self, store: impl Into<StoreContext<'a, T>>, ) -> &'a [i32]

Get access to the raw underlying memory for this list.

This method will return a direct slice into the original wasm module’s linear memory where the data for this slice is stored. This allows the embedder to have efficient access to the underlying memory if needed and avoid copies and such if desired.

Note that multi-byte integers are stored in little-endian format so portable processing of this slice must be aware of the host’s byte-endianness. The from_le constructors in the Rust standard library should be suitable for converting from little-endian.

§Panics

Panics if the store provided is not the one from which this slice originated.

source§

impl WasmList<i64>

source

pub fn as_le_slice<'a, T: 'a>( &self, store: impl Into<StoreContext<'a, T>>, ) -> &'a [i64]

Get access to the raw underlying memory for this list.

This method will return a direct slice into the original wasm module’s linear memory where the data for this slice is stored. This allows the embedder to have efficient access to the underlying memory if needed and avoid copies and such if desired.

Note that multi-byte integers are stored in little-endian format so portable processing of this slice must be aware of the host’s byte-endianness. The from_le constructors in the Rust standard library should be suitable for converting from little-endian.

§Panics

Panics if the store provided is not the one from which this slice originated.

source§

impl WasmList<u8>

source

pub fn as_le_slice<'a, T: 'a>( &self, store: impl Into<StoreContext<'a, T>>, ) -> &'a [u8]

Get access to the raw underlying memory for this list.

This method will return a direct slice into the original wasm module’s linear memory where the data for this slice is stored. This allows the embedder to have efficient access to the underlying memory if needed and avoid copies and such if desired.

Note that multi-byte integers are stored in little-endian format so portable processing of this slice must be aware of the host’s byte-endianness. The from_le constructors in the Rust standard library should be suitable for converting from little-endian.

§Panics

Panics if the store provided is not the one from which this slice originated.

source§

impl WasmList<u16>

source

pub fn as_le_slice<'a, T: 'a>( &self, store: impl Into<StoreContext<'a, T>>, ) -> &'a [u16]

Get access to the raw underlying memory for this list.

This method will return a direct slice into the original wasm module’s linear memory where the data for this slice is stored. This allows the embedder to have efficient access to the underlying memory if needed and avoid copies and such if desired.

Note that multi-byte integers are stored in little-endian format so portable processing of this slice must be aware of the host’s byte-endianness. The from_le constructors in the Rust standard library should be suitable for converting from little-endian.

§Panics

Panics if the store provided is not the one from which this slice originated.

source§

impl WasmList<u32>

source

pub fn as_le_slice<'a, T: 'a>( &self, store: impl Into<StoreContext<'a, T>>, ) -> &'a [u32]

Get access to the raw underlying memory for this list.

This method will return a direct slice into the original wasm module’s linear memory where the data for this slice is stored. This allows the embedder to have efficient access to the underlying memory if needed and avoid copies and such if desired.

Note that multi-byte integers are stored in little-endian format so portable processing of this slice must be aware of the host’s byte-endianness. The from_le constructors in the Rust standard library should be suitable for converting from little-endian.

§Panics

Panics if the store provided is not the one from which this slice originated.

source§

impl WasmList<u64>

source

pub fn as_le_slice<'a, T: 'a>( &self, store: impl Into<StoreContext<'a, T>>, ) -> &'a [u64]

Get access to the raw underlying memory for this list.

This method will return a direct slice into the original wasm module’s linear memory where the data for this slice is stored. This allows the embedder to have efficient access to the underlying memory if needed and avoid copies and such if desired.

Note that multi-byte integers are stored in little-endian format so portable processing of this slice must be aware of the host’s byte-endianness. The from_le constructors in the Rust standard library should be suitable for converting from little-endian.

§Panics

Panics if the store provided is not the one from which this slice originated.

Trait Implementations§

Auto Trait Implementations§

§

impl<T> Freeze for WasmList<T>

§

impl<T> !RefUnwindSafe for WasmList<T>

§

impl<T> Send for WasmList<T>
where T: Send,

§

impl<T> Sync for WasmList<T>
where T: Sync,

§

impl<T> Unpin for WasmList<T>
where T: Unpin,

§

impl<T> !UnwindSafe for WasmList<T>

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> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

impl<T> Pointable for T

source§

const ALIGN: usize = _

The alignment of pointer.
source§

type Init = T

The type for initializers.
source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> Same for T

source§

type Output = T

Should always be Self
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.