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
sourceimpl Table
impl Table
sourcepub fn new(store: &Store, ty: TableType, init: Val) -> Result<Table>
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 inty
- 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.
sourcepub fn ty(&self) -> TableType
pub fn ty(&self) -> TableType
Returns the underlying type of this table, including its element type as well as the maximum/minimum lower bounds.
sourcepub fn get(&self, index: u32) -> Option<Val>
pub fn get(&self, index: u32) -> Option<Val>
Returns the table element value at index
.
Returns None
if index
is out of bounds.
sourcepub fn set(&self, index: u32, val: Val) -> Result<()>
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.
sourcepub fn grow(&self, delta: u32, init: Val) -> Result<u32>
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.
Trait Implementations
Auto Trait Implementations
impl !RefUnwindSafe for Table
impl !Send for Table
impl !Sync for Table
impl Unpin for Table
impl !UnwindSafe for Table
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Pointable for T
impl<T> Pointable for T
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcepub fn to_owned(&self) -> T
pub fn to_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. Read more
sourcepub fn clone_into(&self, target: &mut T)
pub fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more