expression

Distinguish a module from its instances

A compiled module describes executable code and imports. Instantiation binds imports and creates runtime state. Two instances may hold independent state unless they intentionally share imported resources. This host-side Rust model uses two values, not real Wasm instances. Expected host stdout (not executed): first: 1, second: 0 Common mistake: Assuming every instance shares the same mutable state.

Formal Syntax & Structure

rust syntaxrust
WebAssembly.Module → WebAssembly.Instance (host API)

Working Example

Example Snippetrust
struct Instance { count: u32 }fn main() {    let mut first = Instance { count: 0 };    let second = Instance { count: 0 };    first.count += 1;    println!("first: {}, second: {}", first.count, second.count);}
Rust Reference