wasm-actor-bridge
Typed, zero-copy Web Worker bridge for Rust/WASM actor systems.
Overview
wasm-actor-bridge provides a generic actor-model bridge between a main-thread supervisor
and a Web Worker. Commands and events are typed via serde; binary payloads are transferred
zero-copy via ArrayBuffer. Supports both fire-and-forget and request/response (RPC)
patterns. The worker side implements a single WorkerActor trait; the library handles all
message serialisation, correlation, and lifecycle management.
Features
WorkerHandle<Cmd, Evt>—Send + Sync + Clonehandle for commands and RPC callsCallHandle<Evt>— RPC future with cancel-on-drop (firesCancellationToken)EventStream<Evt>—futures::Streamof uncorrelated worker eventsSupervisorBuilder— validated builder for spawning workers with bounded channelsWorkerPool<Cmd, Evt>— pool of N workers with round-robin or pinned routingCancellationToken— cooperative cancellation propagated to actor handlersContext<Evt>—Clone + 'staticresponse context for worker actorsWorkerActortrait — generic typed dispatch with associatedInittype- Zero-copy binary transfer —
send_with_bytes()/ctx.respond_bytes() - RAII cleanup —
Dropterminates the worker, rejects pending RPCs, closes channels
Installation
[]
= "0.1"
Requires the wasm32-unknown-unknown target for browser builds:
Quick Start
Main thread (supervisor)
use ;
// Spawn a single worker.
let = new
.evt_capacity
.init
.build?;
handle.send?; // fire-and-forget
let status: MyEvt = handle.call.await?; // RPC (cancel-on-drop)
Worker thread (actor)
use ;
;
Examples
See EXAMPLES.md for detailed walkthroughs.
| Example | What it shows |
|---|---|
| Ping–Pong RPC | Single worker, typed RPC round-trip |
| Worker Pool | Round-robin pool with WorkerPool |
| Binary Transfer | Zero-copy ArrayBuffer send/receive |
| Native Testing | Testing actors without a browser |
Further Reading
MSRV
Minimum supported Rust version: 1.94 (edition 2024).
Contributing
See CONTRIBUTING.md.
License
Licensed under either of MIT or Apache-2.0 at your option.