act_zero/lib.rs
1//! # act-zero
2//! An actor system for Rust, designed with several goals in mind:
3//! - No boilerplate.
4//! - Ergonomic.
5//! - Supports standard trait-based static and dynamic polymorphism.
6//! - Embraces async/await.
7//! - Executor agnostic.
8//!
9//! Very little code is required to get started:
10//!
11//! ```
12//! use std::error::Error;
13//!
14//! use futures::executor::LocalPool;
15//! use act_zero::*;
16//!
17//! struct SimpleGreeter {
18//! number_of_greets: i32,
19//! }
20//!
21//! impl Actor for SimpleGreeter {}
22//!
23//! impl SimpleGreeter {
24//! async fn greet(&mut self, name: String) -> ActorResult<String> {
25//! self.number_of_greets += 1;
26//! Produces::ok(format!(
27//! "Hello, {}. You are number {}!",
28//! name, self.number_of_greets
29//! ))
30//! }
31//! }
32//!
33//! fn main() -> Result<(), Box<dyn Error>> {
34//! let mut pool = LocalPool::new();
35//! let spawner = pool.spawner();
36//! pool.run_until(async move {
37//! let actor_ref = Addr::new(
38//! &spawner,
39//! SimpleGreeter {
40//! number_of_greets: 0,
41//! },
42//! )?;
43//!
44//! let greeting = call!(actor_ref.greet("John".into())).await?;
45//! println!("{}", greeting);
46//!
47//! let greeting = call!(actor_ref.greet("Emma".into())).await?;
48//! println!("{}", greeting);
49//! Ok(())
50//! })
51//! }
52//! ```
53//!
54//! For mixing traits and actors, it's recommended to use the `async_trait` crate
55//! to allow using async methods in traits.
56
57#![deny(missing_docs)]
58
59mod actor;
60mod addr;
61mod macros;
62pub mod runtimes;
63pub mod timer;
64mod utils;
65
66pub use actor::*;
67pub use addr::*;
68pub use macros::*;
69pub use utils::*;
70
71#[doc(hidden)]
72pub mod hidden {
73 pub use futures::channel::oneshot;
74 pub use futures::future::FutureExt;
75
76 #[cfg(feature = "tracing")]
77 pub use log::trace;
78
79 #[cfg(not(feature = "tracing"))]
80 #[doc(hidden)]
81 #[macro_export]
82 macro_rules! trace {
83 // Strip out all uses of `trace!`
84 ($($args:tt)*) => {};
85 }
86 #[cfg(not(feature = "tracing"))]
87 pub use trace;
88
89 #[cfg(feature = "tracing")]
90 pub fn type_name_of_val<T: ?Sized>(_val: &T) -> tynm::TypeName<'static> {
91 tynm::TypeName::new::<&T>()
92 }
93 #[cfg(feature = "tracing")]
94 pub fn type_name_of_addr<T: crate::AddrLike>(_val: &T) -> tynm::TypeName<'static> {
95 tynm::TypeName::new::<&T::Actor>()
96 }
97}