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
//! `simpl_actor` - A Rust library for actor-based concurrency, built on Tokio.
//!
//! # Features
//!
//! - **Simple Actor Definition:** Define actors with minimal code using Rust structs and macros.
//! - **Automatic Message Handling:** Leverages Rust's type system and async capabilities.
//! - **Asynchronous & Synchronous Messaging:** Flexible interaction patterns for actors.
//! - **Lifecycle Management:** Hooks for actor initialization, restart, and shutdown.
//!
//! # Quick Start
//!
//! ```
//! use simpl_actor::{actor, Actor, Spawn};
//!
//! #[derive(Actor, Default)]
//! pub struct CounterActor { count: i64 }
//!
//! #[actor]
//! impl CounterActor {
//! #[message]
//! pub fn inc(&mut self, amount: i64) { ... }
//!
//! #[message]
//! pub fn inc(&mut self, amount: i64) { ... }
//!
//! #[message(infallible)]
//! pub fn count(&self) -> i64 { ... }
//! }
//!
//! let counter = CounterActor::new();
//! let actor = counter.spawn();
//!
//! actor.inc(2).await?;
//! actor.dec(1).await?;
//! let count = actor.count().await?;
//! ```
//!
//! # Messaging Variants
//!
//! When you define a message in `simpl_actor`, two variants of the message handling function
//! are automatically for syncronous and asyncronous processing:
//!
//! ```
//! #[actor]
//! impl MyActor {
//! #[message]
//! fn msg(&self) -> Result<i32, Err> {}
//! }
//!
//! // Generates
//! impl MyActorRef {
//! /// Sends the messages, waits for processing, and returns a response.
//! async fn msg(&self) -> Result<i32, SendError>;
//! /// Sends the message after a delay.
//! fn msg_after(&self, delay: Duration) -> JoinHandle<Result<Result<i32, Err>, SendError>>;
//! /// Sends the message asynchronously, not waiting for a response.
//! fn msg_async(&self) -> Result<(), SendError>;
//! /// Sends the message asynchronously after a delay.
//! fn msg_async_after(&self, delay: Duration) -> JoinHandle<Result<(), SendError>>;
//! }
//! ```
//! **The \_after and \_async variants are only generated if the method does not have any lifetimes.**
//!
//! In other words, all parameters must be owned or `&'static` for the async variant to be generated,
//! otherwise the actor might reference deallocated memory causing UB.
pub use ;
pub use *;
pub use *;
pub use *;
pub use *;
pub use *;