pub struct Module<G, const MAX_PAGES: usize, const TABLE_SIZE: usize> {
pub memory: IsolatedMemory<MAX_PAGES>,
pub globals: G,
pub table: Table<TABLE_SIZE>,
}Expand description
A module that defines its own memory (§4.1).
G: transpiler-generated globals struct (one typed field per Wasm global)MAX_PAGES: maximum linear memory size (Wasm pages, 64 KiB each)TABLE_SIZE: maximum indirect call table entries
The transpiler generates an impl block on this struct with the
module’s exported and internal functions.
Fields§
§memory: IsolatedMemory<MAX_PAGES>Owned linear memory — isolated by the Rust type system.
globals: GModule-level global variables.
table: Table<TABLE_SIZE>Indirect call table for call_indirect.
Implementations§
Source§impl<G, const MAX_PAGES: usize, const TABLE_SIZE: usize> Module<G, MAX_PAGES, TABLE_SIZE>
impl<G, const MAX_PAGES: usize, const TABLE_SIZE: usize> Module<G, MAX_PAGES, TABLE_SIZE>
Sourcepub fn try_new(
initial_pages: usize,
globals: G,
table: Table<TABLE_SIZE>,
) -> Result<Self, ConstructionError>
pub fn try_new( initial_pages: usize, globals: G, table: Table<TABLE_SIZE>, ) -> Result<Self, ConstructionError>
Create a new module with the given initial memory size, globals, and table.
The transpiler generates a wrapper that calls this with the correct initial values derived from the Wasm binary (data segments, element segments, global initializers).
§Errors
Returns ConstructionError if initial_pages exceeds MAX_PAGES.
Sourcepub fn try_init(
slot: &mut MaybeUninit<Self>,
initial_pages: usize,
globals: G,
table: Table<TABLE_SIZE>,
) -> Result<(), ConstructionError>
pub fn try_init( slot: &mut MaybeUninit<Self>, initial_pages: usize, globals: G, table: Table<TABLE_SIZE>, ) -> Result<(), ConstructionError>
Initialize a Module in-place within a caller-provided slot.
Unlike try_new, this writes directly into slot without ever creating
a large Result<Self, E> on the call stack. Use this when MAX_PAGES
is large, to avoid stack overflow in debug builds.
§Errors
Returns ConstructionError if initial_pages exceeds MAX_PAGES.