Enum wasmtime_runtime::Table

source ·
pub enum Table {
    Static {
        data: &'static mut [usize],
        size: u32,
        ty: TableElementType,
    },
    Dynamic {
        elements: Vec<usize>,
        ty: TableElementType,
        maximum: Option<u32>,
    },
}
Expand description

Represents an instance’s table.

Variants§

§

Static

A “static” table where storage space is managed externally, currently used with the pooling allocator.

Fields

§data: &'static mut [usize]

Where data for this table is stored. The length of this list is the maximum size of the table.

§size: u32

The current size of the table.

§ty: TableElementType

The type of this table.

§

Dynamic

A “dynamic” table where table storage space is dynamically allocated via malloc (aka Rust’s Vec).

Fields

§elements: Vec<usize>

Dynamically managed storage space for this table. The length of this vector is the current size of the table.

§ty: TableElementType

The type of this table.

§maximum: Option<u32>

Maximum size that elements can grow to.

Implementations§

source§

impl Table

source

pub fn new_dynamic(plan: &TablePlan, store: &mut dyn Store) -> Result<Self>

Create a new dynamic (movable) table instance for the specified table plan.

source

pub fn new_static( plan: &TablePlan, data: &'static mut [usize], store: &mut dyn Store, ) -> Result<Self>

Create a new static (immovable) table instance for the specified table plan.

source

pub fn element_type(&self) -> TableElementType

Returns the type of the elements in this table.

source

pub fn size(&self) -> u32

Returns the number of allocated elements.

source

pub fn maximum(&self) -> Option<u32>

Returns the maximum number of elements at runtime.

Returns None if the table is unbounded.

The runtime maximum may not be equal to the maximum from the table’s Wasm type when it is being constrained by an instance allocator.

source

pub fn init_funcs( &mut self, dst: u32, items: impl ExactSizeIterator<Item = *mut VMCallerCheckedFuncRef>, ) -> Result<(), Trap>

Fill table[dst..] with values from items

Returns a trap error on out-of-bounds accesses.

source

pub fn fill( &mut self, dst: u32, val: TableElement, len: u32, ) -> Result<(), Trap>

Fill table[dst..dst + len] with val.

Returns a trap error on out-of-bounds accesses.

source

pub unsafe fn grow( &mut self, delta: u32, init_value: TableElement, store: &mut dyn Store, ) -> Result<Option<u32>, Error>

Grow table by the specified amount of elements.

Returns the previous size of the table if growth is successful.

Returns None if table can’t be grown by the specified amount of elements, or if the init_value is the wrong kind of table element.

§Unsafety

Resizing the table can reallocate its internal elements buffer. This table’s instance’s VMContext has raw pointers to the elements buffer that are used by Wasm, and they need to be fixed up before we call into Wasm again. Failure to do so will result in use-after-free inside Wasm.

Generally, prefer using InstanceHandle::table_grow, which encapsulates this unsafety.

source

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

Get reference to the specified element.

Returns None if the index is out of bounds.

source

pub fn set(&mut self, index: u32, elem: TableElement) -> Result<(), ()>

Set reference to the specified element.

§Errors

Returns an error if index is out of bounds or if this table type does not match the element type.

source

pub unsafe fn copy( dst_table: *mut Self, src_table: *mut Self, dst_index: u32, src_index: u32, len: u32, ) -> Result<(), Trap>

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 vmtable(&mut self) -> VMTableDefinition

Return a VMTableDefinition for exposing the table to compiled wasm code.

Trait Implementations§

source§

impl Default for Table

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl Drop for Table

source§

fn drop(&mut self)

Executes the destructor for this type. Read more

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> 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, U> TryFrom<U> for T
where 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 T
where 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.