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
