apocalypse/lib.rs
1//! # Apocalypse: Simple Actor framework for Rust.
2//!
3//! Apocalypse is a simple actor framework inspired by actix. The goal is to have a fully asynchronous framework with few disadvantages. A simple working example is the following
4//!
5//! ```rust
6//! use apocalypse::{Hell, Demon};
7//!
8//! // Human demon that echoes a message with its name
9//! struct Human {
10//! name: String
11//! }
12//!
13//! // Demon implementation for the human
14//! impl Demon for Human {
15//! type Input = String;
16//! type Output = String;
17//! async fn handle(&mut self, message: Self::Input) -> Self::Output {
18//! format!("Hey, {} here: {}", self.name, &message)
19//! }
20//! }
21//!
22//! #[tokio::main]
23//! async fn main() {
24//! // We create one demon
25//! let carlos = Human{
26//! name: "Carlos".to_string()
27//! };
28//!
29//! // We create hell for this
30//! let hell = Hell::new();
31//! let (portal, jh) = match hell.ignite().await {
32//! Ok(v) => v,
33//! Err(e) => panic!("Could not light up hell, {}", e)
34//! };
35//!
36//! // We spawn the demon in the running hell through the portal
37//! let location = match portal.spawn(carlos).await {
38//! Ok(v) => v,
39//! Err(e) => panic!("Could not spawn the demon, {}", e)
40//! };
41//!
42//! tokio::spawn(async move {
43//! // We send a message to the demon, and await the response.
44//! let m1 = portal.send(&location, "hello world".to_string()).await.unwrap();
45//! // We print the message just for show
46//! println!("{}", &m1);
47//! // And check that it is correct
48//! assert_eq!("Hey, Carlos here: hello world", &m1);
49//! });
50//!
51//! // We wait for all messages to be processed.
52//! jh.await.unwrap();
53//! }
54//! ```
55
56pub use self::demon::{Demon, Location};
57pub use self::hell::{Hell, HellBuilder, HellStats};
58pub use self::gate::{Gate};
59pub use self::error::Error;
60
61mod demon;
62mod hell;
63mod gate;
64mod error;