#[repr(transparent)]
pub struct Table(_);
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

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()])?;
// ...

Async variant of Table::new. You must use this variant with Stores which have a ResourceLimiterAsync.

Panics

This function will panic when used with a non-async Store

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.

Returns the table element value at index.

Returns None if index is out of bounds.

Panics

Panics if store does not own this table.

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.

Returns the current size of this table.

Panics

Panics if store does not own this table.

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.

Async variant of Table::grow. Required when using a ResourceLimiterAsync.

Panics

This function will panic when used with a non-async Store.

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.

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

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Performs the conversion.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The alignment of pointer.

The type for initializers.

Initializes a with the given initializer. Read more

Dereferences the given pointer. Read more

Mutably dereferences the given pointer. Read more

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

Should always be Self

The resulting type after obtaining ownership.

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

🔬 This is a nightly-only experimental API. (toowned_clone_into)

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

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.