mm1/
lib.rs

1// #![warn(missing_docs)]
2#![warn(rust_2018_idioms)]
3#![warn(unreachable_pub)]
4
5pub mod proto {
6    //! Protocols. Actors interact by communication.
7
8    /// A trait showing that the type implementing it can be sent between the
9    /// actors.
10    pub use mm1_proto::Message;
11    /// A proc-macro attribute to make a message out of a type.
12    ///
13    /// Example:
14    /// ```rust
15    /// #[message]
16    /// struct Accept {
17    ///     reply_to: Address,
18    ///     timeout:  Duration,
19    /// }
20    ///
21    /// #[message]
22    /// struct Accepted {
23    ///     io: Unique<TcpStream>,
24    /// }
25    /// ```
26    pub use mm1_proto::message;
27    #[cfg(feature = "sup")]
28    /// The protocol to communicate with supervisors.
29    /// See [`sup`](crate::sup).
30    pub use mm1_proto_sup as sup;
31    /// The low-level API-to the actor system.
32    /// See [`Call`](crate::core::context::Call).
33    pub use mm1_proto_system as system;
34}
35
36pub mod address {
37    //! Addresses, masks, subnets.
38    //!
39    //! Addresses in `mm1` are used as destinations to send messages to.
40    //! A type `Address` is represented as a `u64` integer, and is very similar
41    //! to IPv4- or IPv6-address, in that the whole space of addresses may be
42    //! split into sub-spaces using netmasks.
43    //!
44    //! > Example:
45    //! >
46    //! > A subnet `aabbccddee000000/40` contains 2^24 addresses: from
47    //! > `aabbccddee000000` to `aabbccddeeFFFFFF`.
48    //!
49    //! The way addresses are written takes page from IPv6's notation: the
50    //! leftmost longest series of consequent zero hex-digits is replaced with a
51    //! `':'`-sign. To improve readability, the address is surrounded by
52    //! corner brackets.
53    //!
54    //! The reasons to choose corner brackets:
55    //! - so that they don't mix visually with IPv6-addresses.
56    //! - so that they do not require additional quotes when used in YAML.
57    //! - so that the addresses remind us a little bit of Erlang PIDs :).
58    //!
59    //! > Example:
60    //! > - `aabbccddee000000/40` shall be written as `<aabbccddee:>/40`.
61    //! > - `ffff000000084b03/64` shall be written as `<ffff:84b03>/64`.
62    //!
63    //! Actors' implementations should treat addresses as opaque types
64    //! (implementing `Message`, `Copy`, `Eq`, `Cmp`, and `Hash`).
65    //!
66    //! The nature of addresses should serve the convenience of the operators,
67    //! and probably ease up the implementation of the multi-node messaging.
68    //!
69    //! So, the default value for the node's subnet is `<ffff:>/16`. This
70    //! probably should be treated as `127.0.0.0/8` in IPv4.
71
72    /// Address — a destination to send messages to.
73    pub use mm1_address::address::Address;
74    pub use mm1_address::address::AddressParseError;
75    pub use mm1_address::pool::{
76        Lease as AddressLease, LeaseError as AddressLeaseError, Pool as AddressPool,
77    };
78    /// Address of a network, i.e. an `Address` in combination with a `NetMask`.
79    pub use mm1_address::subnet::NetAddress;
80    /// Mask — specifies how many leading bits in the address are fixed.
81    pub use mm1_address::subnet::NetMask;
82    pub use mm1_address::subnet::{InvalidMask, MaskParseError, NetAddressParseError};
83}
84
85pub mod common {
86
87    /// A helper to define an error-kind enum
88    pub use mm1_common::impl_error_kind;
89    /// An empty type, i.e. no instance of that type can be produced.
90    pub use mm1_common::types::Never;
91
92    pub mod log {
93        pub use mm1_common::log::*;
94    }
95
96    pub mod error {
97        pub use mm1_common::errors::error_kind::HasErrorKind;
98        pub use mm1_common::errors::error_of::ErrorOf;
99        pub use mm1_common::types::{AnyError, StdError};
100    }
101
102    pub mod future {
103        pub use mm1_common::futures::catch_panic::{CatchPanic, CatchPanicExt};
104        pub use mm1_common::futures::timeout::FutureTimeoutExt;
105    }
106}
107
108pub mod core {
109    //! The API to implement actors.
110
111    pub use mm1_core::tracing;
112
113    pub mod envelope {
114        //! An [`Envelope`] is a type-erasing container for the sent messages.
115
116        /// A type-erasing container for the message that has been sent.
117        pub use mm1_core::envelope::Envelope;
118        /// An opaque type containing some information about the message that
119        /// has been sent.
120        pub use mm1_core::envelope::EnvelopeHeader;
121        /// A macro helping to match an [`Envelope`].
122        pub use mm1_core::envelope::dispatch;
123    }
124
125    pub mod context {
126        //! Actor's behaviour is defined as an async-function that receives an
127        //! exclusive reference to some *context* as its first argument.
128        //! The concrete type of the *context* is supposed to remain unknown to
129        //! the actors: they are to interact with their *contexts* via a set of
130        //! traits, that are defined on a *context*.
131
132        /// Report the completion of the init-phase.
133        pub use mm1_core::context::InitDone;
134        /// Link to/unlink from other actors.
135        pub use mm1_core::context::Linking;
136        /// Provides a current Instant.
137        pub use mm1_core::context::Now;
138        /// Terminate its own execution.
139        pub use mm1_core::context::Quit;
140        /// Start other actors.
141        pub use mm1_core::context::Start;
142        /// A convenience trait to simply send a message to another actor.
143        pub use mm1_core::context::Tell;
144        /// Watch/unwatch the termination of other actors.
145        pub use mm1_core::context::Watching;
146        /// Create another context (probably of a different kind), having
147        /// "bound" to the required address. The exact type of address,
148        /// and the concept of "bind" are (intentionally) defined a bit loosely.
149        /// Examples:
150        /// - `Bind<NetAddress>` — would most likely mean catch all the messages
151        ///   sent to any address within the specified network;
152        /// - `Bind<TypeId>` — handle the requests of certain kind.
153        pub use mm1_core::context::{Bind, BindArgs, BindErrorKind};
154        /// Create another context, having an address distinct from the original
155        /// context's one.
156        pub use mm1_core::context::{Fork, ForkErrorKind};
157        /// Send and receive messages.
158        pub use mm1_core::context::{Messaging, RecvErrorKind, SendErrorKind};
159        /// Stop other actors.
160        pub use mm1_core::context::{ShutdownErrorKind, Stop};
161    }
162}
163
164#[cfg(feature = "ask")]
165pub mod ask {
166    pub use mm1_ask::{Ask, AskErrorKind, Reply};
167
168    pub mod proto {
169        pub type RequestHeader = mm1_proto_ask::RequestHeader;
170        pub type Request<Rq> = mm1_proto_ask::Request<Rq>;
171
172        #[doc(hidden)]
173        pub type ResponseHeader = mm1_proto_ask::ResponseHeader;
174        #[doc(hidden)]
175        pub type Response<Rs> = mm1_proto_ask::Response<Rs>;
176    }
177}
178
179#[cfg(feature = "sup")]
180pub mod sup {
181    //! Supervisors — the actors that manage other actors.
182
183    pub mod common {
184        //! The building blocks shared across different types of supervisors.
185
186        /// A recipe for a child-actor.
187        pub use mm1_sup::common::child_spec::ChildSpec;
188        pub use mm1_sup::common::child_spec::InitType;
189        pub use mm1_sup::common::factory::ActorFactory;
190        /// Multiple-use actor factory.
191        pub use mm1_sup::common::factory::ActorFactoryMut;
192        /// Single-use actor-factory.
193        pub use mm1_sup::common::factory::ActorFactoryOnce;
194
195        pub type RestartIntensity = mm1_sup::common::restart_intensity::RestartIntensity;
196
197        pub use mm1_sup::common::restart_intensity::MaxRestartIntensityReached;
198    }
199
200    pub mod uniform {
201        //! Uniform supervisor — the actor, that supervises the children of the
202        //! same type.
203
204        /// The recipe for a supervisor.
205        pub use mm1_sup::uniform::UniformSup;
206        /// Blanket trait for contexts suitable for running a
207        /// uniform-supervisor.
208        pub use mm1_sup::uniform::UniformSupContext;
209        /// types of a child of a uniform-supervisor.
210        pub use mm1_sup::uniform::child_type;
211        /// The behaviour function of the uniform supervisor actor.
212        pub use mm1_sup::uniform::uniform_sup;
213    }
214
215    pub mod mixed {
216        //! Mixed supervisor — the actor, that supervises the children of
217        //! different types.
218
219        /// Type of the child: `Permanent` | `Temporary`.
220        pub use mm1_sup::mixed::ChildType;
221        /// The recipe for a supervisor.
222        pub use mm1_sup::mixed::MixedSup;
223        /// Blanket trait for contexts suitable for running a mixed-supervisor.
224        pub use mm1_sup::mixed::MixedSupContext;
225        /// Mixed supervisor's failure type.
226        pub use mm1_sup::mixed::MixedSupError;
227        /// The behaviour function of the mixed supervisor actor.
228        pub use mm1_sup::mixed::mixed_sup;
229        /// module with supervision strategies.
230        pub use mm1_sup::mixed::strategy;
231    }
232}
233
234#[cfg(feature = "runtime")]
235pub mod runtime {
236    pub use mm1_node::config;
237    pub use mm1_node::runtime::{Local, Rt};
238}
239
240pub use mm1_runnable as runnable;
241
242#[cfg(feature = "timer")]
243pub mod timer {
244    pub use mm1_timer::v1;
245}
246
247#[cfg(feature = "multinode")]
248pub mod multinode {
249    pub mod proto {
250        pub use mm1_proto_network_management::protocols::{
251            RegisterProtocolRequest, RegisterProtocolResponse,
252        };
253    }
254
255    pub use mm1_multinode::codec::Protocol;
256    pub use mm1_proto_well_known::MULTINODE_MANAGER;
257}
258
259// #[cfg(feature = "multinode")]
260// pub mod message_codec {
261//     pub use mm1_multinode::codecs::Codec;
262// }
263
264#[cfg(feature = "test-util")]
265pub mod test {
266    pub use mm1_test_rt::rt;
267}