Skip to main content

Module

Struct Module 

Source
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

Source

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.)

Source

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.

Source

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.

Source

pub fn from_file(engine: &Engine, file: impl AsRef<Path>) -> Result<Module>

Reads and compiles a module from a file path.

Source

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.

Source

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.

Source

pub unsafe fn deserialize_file( engine: &Engine, path: impl AsRef<Path>, ) -> Result<Module>

Like Module::deserialize but reads the artifact from a file.

§Safety

See Module::deserialize.

Source

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.

Source

pub fn imports(&self) -> impl ExactSizeIterator<Item = ImportType<'_>> + '_

Source

pub fn exports(&self) -> impl ExactSizeIterator<Item = ExportType<'_>> + '_

Source

pub fn get_export(&self, name: &str) -> Option<ExternType>

Source

pub fn name(&self) -> Option<&str>

The module’s name from the name custom section’s module subsection, if present. Mirrors wasmtime::Module::name.

Trait Implementations§

Source§

impl Clone for Module

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Module

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.