liveBook · Manning

Wasmtime store

As explained in Server-Side WebAssembly

A Wasmtime store is a runtime object that holds data and execution state associated with WebAssembly components, modules, and instances.

A Wasmtime store is the runtime container for data associated with a WebAssembly component or module. Hosts create one, attach component state to it, and pass it when invoking guest functions. section 3.3.2 section 3.4.2

The store connects Wasmtime’s engine, host-owned state, linked imports, and component calls. In a Rust host, application state is placed inside a custom State value when the store is created. section 3.4.2

A typical host uses the store in this sequence:

  • Create an engine with the WebAssembly component model enabled. section 3.4.2
  • Construct the store from the engine and initialize host state, such as a HashMap-backed key-value service. section 3.4.2
  • Load the component and connect imported host functionality through a linker. section 3.4.2
  • Pass the mutable store to component instantiation and every guest function call. section 3.4.2

Rust SmartCMS host

A SmartCMS host creates a State containing KeyValue, initializes it with an empty HashMap, and passes the resulting store to App::instantiate and app.call_run. section 3.4.2

Python greeting host

A Python host creates store = wasmtime.Store(), roots the generated greet component with component = greet.Root(store), and supplies the store to component.greet. section 3.3.2

// ...
fn main() {
    // ...
    let mut store = wasmtime::Store::new(&engine, State {
        key_value: KeyValue {
            mem: std::collections::HashMap::new(),
        }
    });
}

Inspect the Rust Store::new call, including the engine and State value that carries the host’s key-value data. section 3.4.2

store = wasmtime.Store()
component = greet.Root(store)

Inspect the compact Python pattern for creating a store and rooting a generated component to it. section 3.3.2

How Server-Side WebAssembly covers it

How deep it goes
Explains creation, state attachment, component rooting, and call-site passing, but does not detail store internals.
Examples
Uses a Rust SmartCMS key-value host and a Python greeting component host as concrete store examples.
What it assumes
Assumes a Wasmtime host project and a generated or bundled WebAssembly component to load and invoke.
What you can do after
Operate Wasmtime by creating a store, attaching host data, rooting or linking a component, and passing the store to calls.
How it connects
Connects stores to Wasmtime engines, WebAssembly components, modules, linkers, host state, and guest-function calls.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Server-Side WebAssembly. The section links point to the parts of the book it draws on.