1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
//! # 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")]
//! ```rust
//! 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]` and `ActorArgs` derive macros
//! - **`remote`**: Enables distributed actor systems via P2P networking
//! - **`monitor`**: Enables actor state monitoring and observation
//! - **`persistence`**: Enables actor state persistence and recovery
//!
//! [iroh]: https://iroh.computer/
extern crate self as theta;
pub
pub
/// The prelude module re-exports the most commonly used types and traits.
///
/// This module contains all the essential types needed for basic actor usage.
/// Most applications should use `use theta::prelude::*;` to import these items.
/// Private re-exports for macro use. Do not use directly.