Expand description
Tairitsu - Generic WASM Component Runtime Engine
This framework provides Docker-like image/container mechanisms for running WASM components. It does not prescribe any specific WIT interface - users define their own.
§Architecture
Image- Represents a compiled WASM component (like a Docker image)Container- Represents a running instance of an Image (like a Docker container)Registry- Manages multiple Images and Containers (like a Docker daemon)WitInterface- User-defined WIT interface trait- [
ContainerBuilder] - Builder pattern for creating containers with custom WIT bindings
§Quick Start
ⓘ
use tairitsu::{Container, GuestInstance, Image};
use bytes::Bytes;
// 1. Define your WIT interface (use wit-bindgen to generate bindings)
// wit-bindgen generates your WIT code...
// 2. Create a WASM image
let wasm_binary = std::fs::read("my_component.wasm")?;
let image = Image::new(Bytes::from(wasm_binary))?;
// 3. Create container (user handles WIT binding)
let container = Container::builder(image)?
.with_guest_initializer(|ctx| {
// Register your WIT interface
MyWit::add_to_linker(ctx.linker, |state| &mut state.my_data)?;
let instance = MyWit::instantiate(ctx.store, ctx.component, ctx.linker)?;
Ok(GuestInstance::new(instance))
})?
.build()?;§Helper Macros
use tairitsu::wit_interface;
// Automatically generate WIT interface code
wit_interface! {
interface filesystem {
read: func(path: String) -> Result<Vec<u8>, String>;
write: func(path: String, data: Vec<u8>) -> Result<(), String>;
}
}Re-exports§
pub use container::Container;pub use container::ContainerState;pub use container::ExportInfo;pub use container::GuestHandlerContext;pub use container::GuestInstance;pub use container::HostState;pub use container::HostStateImpl;pub use container::ImportInfo;pub use dynamic::host_imports::HostImport;pub use dynamic::host_imports::HostImportRegistry;pub use dynamic::ron_to_val;pub use dynamic::val_to_ron;pub use registry::Registry;pub use ron::typed_ron_tool;pub use ron::RonBinding;pub use ron::RonFunctionTool;pub use ron::RonTool;pub use ron::RonToolRegistry;pub use wit::FunctionInfo;pub use wit::WitLoader;pub use wit_helper::GuestInfo;pub use wit_registry::CompositeWitInterface;pub use wit_registry::WitCommand;pub use wit_registry::WitCommandDispatcher;pub use wit_registry::WitCommandHandler;pub use wit_registry::WitInterface;
Modules§
- container
- Container - Generic WASM component container
- dynamic
- Dynamic value conversion layer for WASM Component Model
- registry
- Registry - Manages Images and Containers (similar to Docker registry/daemon)
- ron
- RON serialization layer for dynamic WASM invocation
- wit
- WIT definition loader and inspector
- wit_
helper - WIT binding helper macros and types
- wit_
registry - WIT interface registration system
Macros§
- impl_
wit_ interface - Helper macro to implement
WitInterfacetrait for a single WIT interface - simple_
handler - Macro to quickly create simple command handlers
- stateful_
handler - Macro to quickly create stateful command handlers
- wit_
guest_ impl - Macro to generate complete WIT guest implementation
- wit_
interface - Generates WIT command enums and handlers from WIT interface definitions
- wit_
world - Convenience wrapper around
wasmtime::component::bindgen!.
Structs§
- Component
- A compiled WebAssembly Component.
- Config
- Global configuration options used to create an
Engineand customize its behavior. - Engine
- An
Enginewhich is a global context for compilation and management of wasm modules. - Image
- An Image represents a compiled WASM component that can be instantiated into one or more Containers. Similar to Docker images, an Image is immutable and can be used to create multiple Container instances.
- Linker
- Structure used to link wasm modules/instances together.
- Resource
Table - The
ResourceTabletype maps aResource<T>to itsT. - Store
- A
Storeis a collection of WebAssembly instances and host-defined state. - WasiCtx
- Per-
Storestate which holds state necessary to implement WASI from this crate. - Wasi
CtxBuilder - Builder-style structure used to create a
WasiCtx.
Traits§
Attribute Macros§
- export_
wit - Attribute macro to export a function via WIT for WASM guest modules
Derive Macros§
- WitCommand
Derive - Derives WitCommand trait for an enum, automatically generating Response type and command routing