Crates.io | theta |
lib.rs | theta |
version | 0.1.0-alpha.39 |
created_at | 2025-07-20 03:19:12.771054+00 |
updated_at | 2025-09-18 13:46:20.717534+00 |
description | An Rust Actor Framework |
homepage | |
repository | https://github.com/cwahn/theta |
max_upload_size | |
id | 1760738 |
size | 323,974 |
An async actor framework for Rust
Theta is an ergonomic yet minimal and performant async actor framework which Rust deserves.
tokio::task
and two MPMC channels.ActorRef
is just a MPMC sender.iroh
.ActorRef
could be passed around network boundary as regular data in message.remote
.monitor
.persistence
.cargo add theta
use serde::{Deserialize, Serialize};
use theta::prelude::*;
#[derive(Debug, Clone, ActorArgs)]
struct Counter {
value: i64,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Inc(i64);
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct GetValue;
#[actor("96d9901f-24fc-4d82-8eb8-023153d41074")]
impl Actor for Counter {
type View = Nil;
// Behaviors will generate single enum Msg for the actor
const _: () = {
async |Inc(amount): Inc| { // Behavior can access &mut self
self.value += amount;
};
async |_: GetValue| -> i64 { // Behavior may or may not have return
self.value
};
};
}
#[tokio::main]
async fn main() -> anyhow::Result<()> {
let ctx = RootContext::init_local();
let counter = ctx.spawn(Counter { value: 0 });
let _ = counter.tell(Inc(5)); // Fire-and-forget
let current = counter.ask(GetValue).await?; // Wait for response
println!("Current value: {current}"); // Current value: 5
Ok(())
}
Theta is currently under active development and API is subject to change. Not yet recommended for any serious business.
Result::Err
implementing std::fmt::Display
on tell
to be logged as tracing::error!
to prevent silent failure or code duplicationactor
macro to take identifier as ActorId
Licensed under the MIT License.