Struct wasmtime::Table

source ·
pub struct Table(/* private fields */);
Expand description

A WebAssembly table, or an array of values.

Like Memory a table is an indexed array of values, but unlike Memory it’s an array of WebAssembly reference type values rather than bytes. One of the most common usages of a table is a function table for wasm modules (a funcref table), where each element has the ValType::FuncRef type.

A Table “belongs” to the store that it was originally created within (either via Table::new or via instantiating a Module). Operations on a Table only work with the store it belongs to, and if another store is passed in by accident then methods will panic.

Implementations§

source§

impl Table

source

pub fn new(store: impl AsContextMut, ty: TableType, init: Val) -> Result<Table>

Creates a new Table with the given parameters.

  • store - the owner of the resulting Table
  • ty - the type of this table, containing both the element type as well as the initial size and maximum size, if any.
  • init - the initial value to fill all table entries with, if the table starts with an initial size.
§Errors

Returns an error if init does not match the element type of the table, or if init does not belong to the store provided.

§Panics

This function will panic when used with a Store which has a ResourceLimiterAsync (see also: Store::limiter_async. When using an async resource limiter, use [Table::new_async] instead.

§Examples
let engine = Engine::default();
let mut store = Store::new(&engine, ());

let ty = TableType::new(ValType::FuncRef, 2, None);
let table = Table::new(&mut store, ty, Val::FuncRef(None))?;

let module = Module::new(
    &engine,
    "(module
        (table (import \"\" \"\") 2 funcref)
        (func $f (result i32)
            i32.const 10)
        (elem (i32.const 0) $f)
    )"
)?;

let instance = Instance::new(&mut store, &module, &[table.into()])?;
// ...
source

pub fn ty(&self, store: impl AsContext) -> TableType

Returns the underlying type of this table, including its element type as well as the maximum/minimum lower bounds.

§Panics

Panics if store does not own this table.

source

pub fn get(&self, store: impl AsContextMut, index: u32) -> Option<Val>

Returns the table element value at index.

Returns None if index is out of bounds.

§Panics

Panics if store does not own this table.

source

pub fn set(&self, store: impl AsContextMut, index: u32, val: Val) -> Result<()>

Writes the val provided into index within this table.

§Errors

Returns an error if index is out of bounds, if val does not have the right type to be stored in this table, or if val belongs to a different store.

§Panics

Panics if store does not own this table.

source

pub fn size(&self, store: impl AsContext) -> u32

Returns the current size of this table.

§Panics

Panics if store does not own this table.

source

pub fn grow( &self, store: impl AsContextMut, delta: u32, init: Val, ) -> Result<u32>

Grows the size of this table by delta more elements, initialization all new elements to init.

Returns the previous size of this table if successful.

§Errors

Returns an error if the table cannot be grown by delta, for example if it would cause the table to exceed its maximum size. Also returns an error if init is not of the right type or if init does not belong to store.

§Panics

Panics if store does not own this table.

This function will panic when used with a Store which has a ResourceLimiterAsync (see also: Store::limiter_async). When using an async resource limiter, use [Table::grow_async] instead.

source

pub fn copy( store: impl AsContextMut, dst_table: &Table, dst_index: u32, src_table: &Table, src_index: u32, len: u32, ) -> Result<()>

Copy len elements from src_table[src_index..] into dst_table[dst_index..].

§Errors

Returns an error if the range is out of bounds of either the source or destination tables.

§Panics

Panics if store does not own either dst_table or src_table.

source

pub fn fill( &self, store: impl AsContextMut, dst: u32, val: Val, len: u32, ) -> Result<()>

Fill table[dst..(dst + len)] with the given value.

§Errors

Returns an error if

  • val is not of the same type as this table’s element type,

  • the region to be filled is out of bounds, or

  • val comes from a different Store from this table.

§Panics

Panics if store does not own either dst_table or src_table.

Trait Implementations§

source§

impl Clone for Table

source§

fn clone(&self) -> Table

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Table

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl From<Table> for Extern

source§

fn from(r: Table) -> Self

Converts to this type from the input type.
source§

impl Copy for Table

Auto Trait Implementations§

§

impl Freeze for Table

§

impl RefUnwindSafe for Table

§

impl Send for Table

§

impl Sync for Table

§

impl Unpin for Table

§

impl UnwindSafe for Table

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> CloneToUninit for T
where T: Copy,

source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

impl<T> CloneToUninit for T
where T: Clone,

source§

default unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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.
§

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

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

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

§

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

§

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.