wasmtime::component

Struct WasmList

Source
pub struct WasmList<T> { /* private fields */ }
Available on crate features runtime and component-model only.
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
§

impl<T> Pointable for T

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

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

Initializes a with the given initializer. Read more
§

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

Dereferences the given pointer. Read more
§

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

Mutably dereferences the given pointer. Read more
§

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.