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§

source§

impl Table

source

pub fn create(ty: &TableType) -> WasmEdgeResult<Self>

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");
source

pub fn ty(&self) -> WasmEdgeResult<TableType>

Returns the TableType of the Table.

Error

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

source

pub fn get_data(&self, idx: u32) -> WasmEdgeResult<WasmValue>

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.

source

pub fn set_data(&mut self, data: WasmValue, idx: u32) -> WasmEdgeResult<()>

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.

source

pub fn capacity(&self) -> usize

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);
source

pub fn grow(&mut self, size: u32) -> WasmEdgeResult<()>

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.

source

pub fn as_ptr(&self) -> *const WasmEdge_TableInstanceContext

Available on crate feature ffi only.

Provides a raw pointer to the inner table context.

Trait Implementations§

source§

impl Clone for Table

source§

fn clone(&self) -> Self

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 Drop for Table

source§

fn drop(&mut self)

Executes the destructor for this type. Read more

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§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. 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 Twhere 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> ToOwned for Twhere 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 Twhere 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 Twhere 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.
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V