Skip to main content

Crate tairitsu

Crate tairitsu 

Source
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 WitInterface trait 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 Engine and customize its behavior.
Engine
An Engine which 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.
ResourceTable
The ResourceTable type maps a Resource<T> to its T.
Store
A Store is a collection of WebAssembly instances and host-defined state.
WasiCtx
Per-Store state which holds state necessary to implement WASI from this crate.
WasiCtxBuilder
Builder-style structure used to create a WasiCtx.

Traits§

WasiView
A trait which provides access to the WasiCtx inside the embedder’s T of Store<T>.

Attribute Macros§

export_wit
Attribute macro to export a function via WIT for WASM guest modules

Derive Macros§

WitCommandDerive
Derives WitCommand trait for an enum, automatically generating Response type and command routing