Skip to main content

Table

Struct Table 

Source
pub struct Table<const MAX_SIZE: usize> { /* private fields */ }
Expand description

Indirect call table with a compile-time maximum size.

MAX_SIZE is derived from the Wasm module’s table declaration. Entries are Option<FuncRef>None means the slot is empty (calling it traps with UndefinedElement).

Implementations§

Source§

impl<const MAX_SIZE: usize> Table<MAX_SIZE>

Source

pub fn try_new(initial_size: usize) -> Result<Self, ConstructionError>

Create a new table with initial_size slots, all empty (None).

§Errors

Returns ConstructionError::TableInitialSizeExceedsMax if initial_size > MAX_SIZE.

Source

pub fn size(&self) -> usize

Current number of active table slots.

Source

pub fn get(&self, index: u32) -> WasmResult<FuncRef>

Look up a table entry by index. Returns the FuncRef if present.

  • TableOutOfBounds if index >= active_size
  • UndefinedElement if the slot is None
Source

pub fn set(&mut self, index: u32, entry: Option<FuncRef>) -> WasmResult<()>

Set a table entry. Used during module initialization (element segments).

Returns Err(TableOutOfBounds) if index >= active_size.

Source

pub fn init_elements( &mut self, base: u32, entries: &[(u32, u32)], ) -> WasmResult<()>

Initialize table entries from element segment data.

Writes entries (each as (type_index, func_index)) into consecutive slots starting at base. Replaces per-slot set() calls in generated constructors and propagates bounds errors via ? instead of panicking.

§Errors

Returns Err(TableOutOfBounds) if any slot index is out of range.

Source

pub fn grow(&mut self, delta: u32, init: Option<FuncRef>) -> i32

Grow the table by delta slots, filling new slots with init. Returns the previous size, or -1 on failure.

Auto Trait Implementations§

§

impl<const MAX_SIZE: usize> Freeze for Table<MAX_SIZE>

§

impl<const MAX_SIZE: usize> RefUnwindSafe for Table<MAX_SIZE>

§

impl<const MAX_SIZE: usize> Send for Table<MAX_SIZE>

§

impl<const MAX_SIZE: usize> Sync for Table<MAX_SIZE>

§

impl<const MAX_SIZE: usize> Unpin for Table<MAX_SIZE>

§

impl<const MAX_SIZE: usize> UnsafeUnpin for Table<MAX_SIZE>

§

impl<const MAX_SIZE: usize> UnwindSafe for Table<MAX_SIZE>

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

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.