1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#![feature(generic_associated_types)]
mod envelope;
mod address;
pub use address::{Address, Disconnected};
mod context;
pub use context::Context;
mod manager;
pub use manager::ActorManager;
use std::future::Future;
pub trait Message: Send + 'static {
type Result: Send;
}
pub trait Handler<M: Message>: Actor {
fn handle(&mut self, message: M, ctx: &mut Context<Self>) -> M::Result;
}
pub trait AsyncHandler<M: Message>: Actor {
type Responder<'a>: Future<Output = M::Result> + Send;
fn handle<'a>(&'a mut self, message: M, ctx: &'a mut Context<Self>) -> Self::Responder<'a>;
}
pub trait Actor: 'static + Sized {
fn started(&mut self, _ctx: &mut Context<Self>) {}
fn stopped(&mut self, _ctx: &mut Context<Self>) {}
#[cfg(any(feature = "with-tokio-0_2", feature = "with-async_std-1"))]
fn spawn(self) -> Address<Self>
where
Self: Sized + Send,
{
ActorManager::spawn(self)
}
fn start(self) -> (Address<Self>, ActorManager<Self>)
where
Self: Sized,
{
ActorManager::start(self)
}
}