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 = "server")]
180pub mod server {
181    //! Server — a standard way to implement a long-living actor that handles
182    //! inbound messages.
183
184    /// create a new server builder
185    pub use mm1_server::new;
186    pub mod behaviour {
187        /// Handle inbound messages.
188        pub use mm1_server::OnMessage;
189        /// Handle inbound requests (see `mm1::ask`).
190        pub use mm1_server::OnRequest;
191        /// Result of handling a message/request.
192        pub use mm1_server::Outcome;
193    }
194}
195
196#[cfg(feature = "sup")]
197pub mod sup {
198    //! Supervisors — the actors that manage other actors.
199
200    pub mod common {
201        //! The building blocks shared across different types of supervisors.
202
203        /// A recipe for a child-actor.
204        pub use mm1_sup::common::child_spec::ChildSpec;
205        pub use mm1_sup::common::child_spec::InitType;
206        pub use mm1_sup::common::factory::ActorFactory;
207        /// Multiple-use actor factory.
208        pub use mm1_sup::common::factory::ActorFactoryMut;
209        /// Single-use actor-factory.
210        pub use mm1_sup::common::factory::ActorFactoryOnce;
211
212        pub type RestartIntensity = mm1_sup::common::restart_intensity::RestartIntensity;
213
214        pub use mm1_sup::common::restart_intensity::MaxRestartIntensityReached;
215    }
216
217    pub mod uniform {
218        //! Uniform supervisor — the actor, that supervises the children of the
219        //! same type.
220
221        /// The recipe for a supervisor.
222        pub use mm1_sup::uniform::UniformSup;
223        /// Blanket trait for contexts suitable for running a
224        /// uniform-supervisor.
225        pub use mm1_sup::uniform::UniformSupContext;
226        /// types of a child of a uniform-supervisor.
227        pub use mm1_sup::uniform::child_type;
228        /// The behaviour function of the uniform supervisor actor.
229        pub use mm1_sup::uniform::uniform_sup;
230    }
231
232    pub mod mixed {
233        //! Mixed supervisor — the actor, that supervises the children of
234        //! different types.
235
236        /// Type of the child: `Permanent` | `Temporary`.
237        pub use mm1_sup::mixed::ChildType;
238        /// The recipe for a supervisor.
239        pub use mm1_sup::mixed::MixedSup;
240        /// Blanket trait for contexts suitable for running a mixed-supervisor.
241        pub use mm1_sup::mixed::MixedSupContext;
242        /// Mixed supervisor's failure type.
243        pub use mm1_sup::mixed::MixedSupError;
244        /// The behaviour function of the mixed supervisor actor.
245        pub use mm1_sup::mixed::mixed_sup;
246        /// module with supervision strategies.
247        pub use mm1_sup::mixed::strategy;
248    }
249}
250
251#[cfg(feature = "runtime")]
252pub mod runtime {
253    pub use mm1_node::config;
254    pub use mm1_node::runtime::{Local, Rt};
255}
256
257pub use mm1_runnable as runnable;
258
259#[cfg(feature = "timer")]
260pub mod timer {
261    pub use mm1_timer::v1;
262}
263
264#[cfg(feature = "multinode")]
265pub mod multinode {
266    pub mod proto {
267        pub use mm1_proto_network_management::protocols::{
268            RegisterProtocolRequest, RegisterProtocolResponse,
269        };
270    }
271
272    pub use mm1_multinode::codec::Protocol;
273    pub use mm1_proto_well_known::MULTINODE_MANAGER;
274}
275
276// #[cfg(feature = "multinode")]
277// pub mod message_codec {
278//     pub use mm1_multinode::codecs::Codec;
279// }
280
281#[cfg(feature = "test-util")]
282pub mod test {
283    pub use mm1_test_rt::rt;
284}