pub struct Module(/* private fields */);Expand description
A compiled, reusable WebAssembly module. Shareable across stores of the same
engine; cloning is a cheap Arc bump.
Implementations§
Source§impl Module
impl Module
Sourcepub fn new(engine: &Engine, bytes: impl AsRef<[u8]>) -> Result<Module>
pub fn new(engine: &Engine, bytes: impl AsRef<[u8]>) -> Result<Module>
Parses, validates, and compiles a module from a .wasm binary.
(Unlike wasmtime with its wat feature, we accept binary only; convert
.wat with the wat crate first.)
Sourcepub fn from_binary(engine: &Engine, binary: &[u8]) -> Result<Module>
pub fn from_binary(engine: &Engine, binary: &[u8]) -> Result<Module>
Like Module::new but accepts binary .wasm only.
Validation is fused into the decode/compile pass (see [parse::parse_module]), so the
binary is walked once — not validated by a separate full pass and then re-parsed.
Sourcepub fn new_with_limits(
engine: &Engine,
bytes: impl AsRef<[u8]>,
limits: &ModuleLimits,
) -> Result<Module>
pub fn new_with_limits( engine: &Engine, bytes: impl AsRef<[u8]>, limits: &ModuleLimits, ) -> Result<Module>
Like Module::new but with explicit per-module ModuleLimits — the entry point for
trusted/curated packages that the embedder allows a higher (but still finite)
complexity ceiling than the engine’s untrusted-tier default (#32).
Additive deviation from wasmtime — there is no analog in wasmtime.
Sourcepub fn from_file(engine: &Engine, file: impl AsRef<Path>) -> Result<Module>
pub fn from_file(engine: &Engine, file: impl AsRef<Path>) -> Result<Module>
Reads and compiles a module from a file path.
Sourcepub fn serialize(&self) -> Result<Vec<u8>>
pub fn serialize(&self) -> Result<Vec<u8>>
Serializes this compiled module to the binary artifact format consumed by
Module::deserialize. The artifact is the compiled form, not the original
wasm — restoring it skips validation + compilation.
Sourcepub unsafe fn deserialize(
engine: &Engine,
bytes: impl AsRef<[u8]>,
) -> Result<Module>
pub unsafe fn deserialize( engine: &Engine, bytes: impl AsRef<[u8]>, ) -> Result<Module>
Restores a Module from an artifact produced by Module::serialize /
Engine::precompile_module, without re-validating or recompiling.
§Safety
Matches wasmtime::Module::deserialize: the artifact must be a trusted blob
produced by a matching version of this crate (it is not guest-reachable input).
A corrupted artifact cannot cause undefined behavior here — the interpreter runs
in safe Rust with bounds-checked dispatch, so the worst case is a trap rather than
memory unsafety — but cross-version/garbage blobs are rejected up front.
The validation-time module-size ceiling (#32) is intentionally not applied here:
the artifact is a trusted, embedder-only blob (not guest-reachable), matching wasmtime’s
unsafe deserialize contract.
Sourcepub fn validate(engine: &Engine, binary: &[u8]) -> Result<()>
pub fn validate(engine: &Engine, binary: &[u8]) -> Result<()>
Validates a module without compiling it. Applies the engine’s untrusted-tier
module-size ceiling (Config::max_module_bytes, #32) before parsing.