heph/
lib.rs

1//! Heph, derived from [Hephaestus], is the Greek god of blacksmiths,
2//! metalworking, carpenters, craftsmen, artisans, sculptors, metallurgy, fire,
3//! and volcanoes. Well this crate has very little to do with Greek gods, but I
4//! needed a name.
5//!
6//! [Hephaestus]: https://en.wikipedia.org/wiki/Hephaestus
7//!
8//! ## About
9//!
10//! Heph is an [actor] framework based on asynchronous functions. Such an
11//! asynchronous function looks like this:
12//!
13//! ```
14//! # use heph::actor;
15//! # use heph_rt::ThreadLocal;
16//! #
17//! async fn actor(mut ctx: actor::Context<String, ThreadLocal>) {
18//!     // Receive a message.
19//!     if let Ok(msg) = ctx.receive_next().await {
20//!         // Print the message.
21//!         println!("got a message: {}", msg);
22//!     }
23//! }
24//! #
25//! # drop(actor); // Silence dead code warnings.
26//! ```
27//!
28//! Heph uses an event-driven, non-blocking I/O, share nothing design. But what
29//! do all those buzzwords actually mean?
30//!
31//!  - *Event-driven*: Heph does nothing by itself, it must first get an event
32//!    before it starts doing anything. For example when using a `TcpListener`
33//!    it waits on a notification from the OS saying the `TcpListener` is ready
34//!    before trying to accept connections.
35//!  - *Non-blocking I/O*: normal I/O operations need to wait (block) until the
36//!    operation can complete. Using non-blocking, or asynchronous, I/O means
37//!    that rather then waiting for the operation to complete we'll do some
38//!    other, more useful, work and try the operation later.
39//!  - *Share nothing*: a lot of application share data across multiple threads.
40//!    To do this safely we need to protect it from data races, via a [`Mutex`]
41//!    or by using [atomic] operations. Heph is designed to not share any data.
42//!    Each actor is responsible for its own memory and cannot access memory
43//!    owned by other actors. Instead communication is done via sending
44//!    messages, see the [actor model].
45//!
46//! [actor]: https://en.wikipedia.org/wiki/Actor_model
47//! [`Mutex`]: std::sync::Mutex
48//! [atomic]: std::sync::atomic
49//! [actor model]: https://en.wikipedia.org/wiki/Actor_model
50//!
51//! ## Getting started
52//!
53//! There are two ways to get starting with Heph. If you like to see examples,
54//! take a look at the [examples] in the examples directory of the source code.
55//! If you like to learn more about some of the core concepts of Heph start with
56//! the [Quick Start] guide.
57//!
58//! [examples]: https://github.com/Thomasdezeeuw/heph/blob/master/examples/README.md
59//! [Quick Start]: crate::quick_start
60//!
61//! ## Features
62//!
63//! This crate has one optional: `test`. The `test` feature will enable the
64//! `test` module which adds testing facilities.
65
66#![feature(const_option, doc_auto_cfg, doc_cfg_hide, never_type)]
67#![warn(
68    anonymous_parameters,
69    bare_trait_objects,
70    missing_debug_implementations,
71    missing_docs,
72    rust_2018_idioms,
73    trivial_numeric_casts,
74    unused_extern_crates,
75    unused_import_braces,
76    unused_qualifications,
77    unused_results,
78    variant_size_differences
79)]
80// Disallow warnings when running tests.
81#![cfg_attr(test, deny(warnings))]
82// Disallow warnings in examples, we want to set a good example after all.
83#![doc(test(attr(deny(warnings))))]
84// The `cfg(any(test, feature = "test"))` attribute creates a doc element
85// staying that it's only supporting "using test or test", that is a bit
86// confusing. So we hide those parts and instead manually replace all of them
87// with: `doc(cfg(feature = "test"))`. That will stay it's only supported using
88// the test feature.
89#![doc(cfg_hide(any(test, feature = "test")))]
90
91pub mod actor;
92pub mod actor_ref;
93pub mod messages;
94pub mod quick_start;
95pub mod supervisor;
96#[cfg(any(test, feature = "test"))]
97pub mod test;
98
99#[doc(no_inline)]
100pub use actor::{Actor, NewActor};
101#[doc(no_inline)]
102pub use actor_ref::ActorRef;
103#[doc(no_inline)]
104pub use supervisor::{Supervisor, SupervisorStrategy};