No description
Find a file
Zachery Aaron Shores-Chmielewski 7c7947c823 feat: actor addresses, Ctx abstraction, pools, and more
Fleshing out the architecture before abstracting into components amenable to api-based test harnesses for fuzz and optimization working loops.
2026-02-05 22:54:03 +07:00
benches feat: actor addresses, Ctx abstraction, pools, and more 2026-02-05 22:54:03 +07:00
examples feat: actor addresses, Ctx abstraction, pools, and more 2026-02-05 22:54:03 +07:00
src feat: actor addresses, Ctx abstraction, pools, and more 2026-02-05 22:54:03 +07:00
tests feat: actor addresses, Ctx abstraction, pools, and more 2026-02-05 22:54:03 +07:00
.gitignore feat(wip): add to design pages 2026-01-27 20:01:35 +07:00
ARCHITECTURE.md feat: mailbox 2026-02-05 21:22:36 +07:00
Cargo.lock feat: actor addresses, Ctx abstraction, pools, and more 2026-02-05 22:54:03 +07:00
Cargo.toml feat: actor addresses, Ctx abstraction, pools, and more 2026-02-05 22:54:03 +07:00
README.md feat: actor addresses, Ctx abstraction, pools, and more 2026-02-05 22:54:03 +07:00
TODOs.md feat(wip): add to design pages 2026-01-27 20:01:35 +07:00

swactor

(S)mall (W)ASM-compatible (actor) library

Quick example

use swactor::{
    Ctx,
    actor::{ActorAddress, ActorInterface},
    runtime::{Runtime, RuntimeConfig},
};

#[derive(Debug, Default)]
struct Greeter { num_greeted: usize }

#[derive(Debug, Default, Clone)]
struct GreetMessage { who: String, return_addr: ActorAddress }

#[derive(Debug, Default, Clone)]
struct GreetResponse(String);

impl ActorInterface for Greeter {
    type Incoming = GreetMessage;
    type Response = GreetResponse;

    fn handle(&mut self, ctx: &Ctx, msg: GreetMessage) {
        let res = GreetResponse(format!("Hello, {}!", msg.who));
        self.num_greeted += 1;
        if let Err(_) = ctx.send(msg.return_addr, res) {
            self.num_greeted -= 1;
        }
    }
}

fn main() {
    let rt = Runtime::new(RuntimeConfig::default());
    let addr = rt.spawn(Greeter::default()).expect("failed to spawn");

    let inbox = rt.new_inbox::<GreetResponse>().unwrap();
    rt.send_to(addr, GreetMessage {
        who: "world".into(),
        return_addr: *inbox.addr(),
    }).unwrap();

    for _ in 0..3 { rt.tick(); }
    let resp = inbox.try_recv().expect("should have response");
    println!("{}", resp.0); // "Hello, world!"
}

Build & test

cargo build
cargo test
cargo test --features stress   # stress tests
cargo run --bin bench --release # benchmarks
cargo run --example hello