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>
impl<T: Lift> WasmList<T>
sourcepub fn get(&self, store: impl AsContextMut, index: usize) -> Option<Result<T>>
pub fn get(&self, store: impl AsContextMut, index: usize) -> Option<Result<T>>
Gets the n
th 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.
sourcepub fn iter<'a, U: 'a>(
&'a self,
store: impl Into<StoreContextMut<'a, U>>,
) -> impl ExactSizeIterator<Item = Result<T>> + 'a
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>
impl WasmList<i8>
sourcepub fn as_le_slice<'a, T: 'a>(
&self,
store: impl Into<StoreContext<'a, T>>,
) -> &'a [i8]
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>
impl WasmList<i16>
sourcepub fn as_le_slice<'a, T: 'a>(
&self,
store: impl Into<StoreContext<'a, T>>,
) -> &'a [i16]
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>
impl WasmList<i32>
sourcepub fn as_le_slice<'a, T: 'a>(
&self,
store: impl Into<StoreContext<'a, T>>,
) -> &'a [i32]
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>
impl WasmList<i64>
sourcepub fn as_le_slice<'a, T: 'a>(
&self,
store: impl Into<StoreContext<'a, T>>,
) -> &'a [i64]
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>
impl WasmList<u8>
sourcepub fn as_le_slice<'a, T: 'a>(
&self,
store: impl Into<StoreContext<'a, T>>,
) -> &'a [u8] ⓘ
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>
impl WasmList<u16>
sourcepub fn as_le_slice<'a, T: 'a>(
&self,
store: impl Into<StoreContext<'a, T>>,
) -> &'a [u16]
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>
impl WasmList<u32>
sourcepub fn as_le_slice<'a, T: 'a>(
&self,
store: impl Into<StoreContext<'a, T>>,
) -> &'a [u32]
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>
impl WasmList<u64>
sourcepub fn as_le_slice<'a, T: 'a>(
&self,
store: impl Into<StoreContext<'a, T>>,
) -> &'a [u64]
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§
impl<T: ComponentType> ComponentType for WasmList<T>
impl<T: Lift> Lift for WasmList<T>
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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