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>
impl<const MAX_SIZE: usize> Table<MAX_SIZE>
Sourcepub fn try_new(initial_size: usize) -> Result<Self, ConstructionError>
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.
Sourcepub fn get(&self, index: u32) -> WasmResult<FuncRef>
pub fn get(&self, index: u32) -> WasmResult<FuncRef>
Look up a table entry by index. Returns the FuncRef if present.
TableOutOfBoundsifindex >= active_sizeUndefinedElementif the slot isNone
Sourcepub fn set(&mut self, index: u32, entry: Option<FuncRef>) -> WasmResult<()>
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.
Sourcepub fn init_elements(
&mut self,
base: u32,
entries: &[(u32, u32)],
) -> WasmResult<()>
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.