Expand description
§Theta: An Async Actor Framework for Rust
Theta is an ergonomic yet minimal and performant async actor framework for Rust.
§Key Features
- Async-first: Built on top of
tokio
, actors are lightweight tasks with MPMC communication - Built-in remote capabilities: Distributed actor systems powered by P2P protocol (iroh)
- Built-in monitoring: Monitor actor state changes and lifecycle events
- Built-in persistence: Seamless actor snapshots and recovery
- Type-safe messaging: Compile-time guarantees for message handling
- Ergonomic macros: Simplified actor definition with the
#[actor]
attribute
§Quick Start
#[cfg(feature = “full”)]
use serde::{Deserialize, Serialize};
use theta::prelude::*;
// Define actor state
#[derive(Debug, Clone, ActorArgs)]
struct Counter { value: i64 }
// Define messages
#[derive(Debug, Clone, Serialize, Deserialize)]
struct Inc(i64);
#[derive(Debug, Clone, Serialize, Deserialize)]
struct GetValue;
// Implement actor behavior
#[actor("96d9901f-24fc-4d82-8eb8-023153d41074")]
impl Actor for Counter {
const _: () = {
async |Inc(amount): Inc| {
self.value += amount;
};
async |_: GetValue| -> i64 {
self.value
};
};
}
#[tokio::main]
async fn main() -> anyhow::Result<()> {
let ctx = RootContext::init_local();
let counter = ctx.spawn(Counter { value: 0 });
counter.tell(Inc(5))?; // Fire-and-forget
let current = counter.ask(GetValue).await?; // Request-response
println!("Current value: {current}"); // Current value: 5
Ok(())
}
§Features
macros
(default): Enables the#[actor]
andActorArgs
derive macrosremote
: Enables distributed actor systems via P2P networkingmonitor
: Enables actor state monitoring and observationpersistence
: Enables actor state persistence and recovery
Modules§
- actor
- actor_
ref - Actor reference types for communication with actors.
- base
- Base types and utilities used throughout the framework.
- context
- message
- Message types and traits for actor communication.
- monitor
- Actor monitoring and observation capabilities.
- persistence
- Actor persistence capabilities for state snapshots and recovery.
- prelude
- The prelude module re-exports the most commonly used types and traits.
- remote
- Remote actor communication over peer-to-peer networks.