Struct 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 values rather than bytes. One of the most common usages of a table is a function table for wasm modules, where each element has the Func type.

Tables, like globals, are not threadsafe and can only be used on one thread. Tables can be grown in size and each element can be read/written.

§Table and Clone

Tables are internally reference counted so you can clone a Table. The cloning process only performs a shallow clone, so two cloned Table instances are equivalent in their functionality.

Implementations§

Source§

impl Table

Source

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

Creates a new Table with the given parameters.

  • store - a global cache to store information in
  • 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.

Source

pub fn ty(&self) -> TableType

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

Source

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

Returns the table element value at index.

Returns None if index is out of bounds.

Source

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

Writes the val provided into index within this table.

§Errors

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

Source

pub fn size(&self) -> u32

Returns the current size of this table.

Source

pub fn grow(&self, 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.

Source

pub fn copy( 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.

Source

pub fn fill(&self, 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.

Trait Implementations§

Source§

impl Clone for Table

Source§

fn clone(&self) -> Table

Returns a duplicate 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 From<Table> for Extern

Source§

fn from(r: Table) -> Self

Converts to this type from the input type.

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

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

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

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.