robots/actors/mod.rs
1pub use std::any::Any;
2
3pub use self::actor_cell::{ActorCell, ActorContext, ControlMessage, InnerMessage, SystemMessage};
4pub use self::actor_ref::{ActorPath, ActorRef};
5pub use self::actor_system::ActorSystem;
6pub use self::props::Props;
7
8/// Module for ActorRef and CanReceive, the interface given to the user to interract with actors.
9pub mod actor_ref;
10
11/// Module for the ActorSystem.
12pub mod actor_system;
13
14/// Module for Actor factories (Props).
15pub mod props;
16
17/// Module with the internals of Actors.
18pub mod actor_cell;
19
20/// Module containing the original actor.
21mod cthulhu;
22
23/// Module containing the root actor pattern, used for the `user actor` and the `systel actor`.
24mod root_actor;
25
26/// Module with the name resolver actor.
27mod name_resolver;
28
29/// Robots Future implementation.
30mod future;
31
32/// Trait to be implemented by messages, this is automatically given if a struct is
33/// already `Clone + Send + Sync + 'static + Any`.
34pub trait Message: Clone + Send + Sync + 'static + Any {}
35impl<T> Message for T where T: Clone + Send + Sync + 'static + Any
36{}
37
38/// Trait to be implemented by args, this is automatically given if a struct is
39/// already `Clone + Send + Sync + 'static + Any`.
40pub trait Arguments: Clone + Send + Sync + 'static {}
41impl<T> Arguments for T where T: Clone + Send + Sync + 'static
42{}
43
44/// This is the trait to implement to become an Actor.
45///
46/// Normaly only the receive method has to be implemented.
47pub trait Actor: Send + Sync + 'static {
48
49 /// Single method to be implemented for an Actor.
50 ///
51 /// This defines the Actor's behaviour.
52 // We have a Box<Any> in the API even though that is a Box<Message> in reality, this is
53 // done in order to have nicer code for the downcasts (indeed, I can't implement downcast
54 // methods for Box<Message>).
55 // Checks for sending data with the Message trait is done in the sending phase.
56 fn receive(&self, message: Box<Any>, context: ActorCell);
57
58 /// Method called before the Actor is started.
59 fn pre_start(&self, _context: ActorCell) {}
60
61 /// Method called after the Actor is stopped.
62 fn post_stop(&self) {}
63
64 /// Method called before the Actor is restarted.
65 fn pre_restart(&self, _context: ActorCell) {
66 self.post_stop();
67 }
68
69 /// Method called after the Actor is restarted.
70 fn post_restart(&self, context: ActorCell) {
71 self.pre_start(context);
72 }
73}