Struct wasmedge_sys::Table

source ·
pub struct Table { /* private fields */ }
Expand description

A WasmEdge Table defines a WebAssembly table instance described by its type. A table is an array-like structure and stores function references.

This example shows how to use Table to store and retrieve function references.

Implementations§

Creates a new Table to be associated with the given element type and the size.

Arguments
  • ty specifies the type of the new Table.
Error
  • If fail to create the table instance, then WasmEdgeError::Table(TableError::Create)(crate::error::TableError) is returned.
Example
use wasmedge_sys::{TableType, Table};
use wasmedge_types::RefType;

// create a TableType instance
let ty = TableType::create(RefType::FuncRef, 10, Some(20)).expect("fail to create a TableType");

// create a Table instance
let table = Table::create(&ty).expect("fail to create a Table");

Returns the TableType of the Table.

Error

If fail to get type, then an error is returned.

Returns the element value at a specific position in the Table.

Arguments
  • idx specifies the position in the Table, at which the WasmValue is returned.
Error

If fail to get the data, then an error is returned.

Sets a new element value at a specific position in the Table.

Arguments
  • data specifies the new data.

  • idx specifies the position of the new data to be stored in the Table.

Error

If fail to set data, then an error is returned.

Returns the capacity of the Table.

Example
use wasmedge_sys::{TableType, Table};
use wasmedge_types::RefType;

// create a TableType instance and a Table
let ty = TableType::create(RefType::FuncRef, 10, Some(20)).expect("fail to create a TableType");
let table = Table::create(&ty).expect("fail to create a Table");

// check capacity
assert_eq!(table.capacity(), 10);

Increases the capacity of the Table.

After growing, the new capacity must be in the range defined by limit when the table is created.

Argument
  • size specifies the size to be added to the Table.
Error

If fail to increase the size of the Table, then an error is returned.

Provides a raw pointer to the inner table context.

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
Executes the destructor for this type. Read more

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 resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
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.