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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
use actor::Actor;
use address::SyncAddress;
use context::Context;
use handler::ResponseType;
pub struct SystemExit(pub i32);
impl ResponseType for SystemExit {
type Item = ();
type Error = ();
}
pub struct StopArbiter(pub i32);
impl ResponseType for StopArbiter {
type Item = ();
type Error = ();
}
pub struct StartActor<A: Actor>(Box<FnBox<A>>);
impl<A: Actor> ResponseType for StartActor<A> {
type Item = SyncAddress<A>;
type Error = ();
}
impl<A: Actor<Context=Context<A>>> StartActor<A>
{
pub fn new<F>(f: F) -> Self
where F: FnOnce(&mut Context<A>) -> A + Send + 'static
{
StartActor(Box::new(|| A::create(f)))
}
pub(crate) fn call(self) -> SyncAddress<A> {
self.0.call_box()
}
}
trait FnBox<A: Actor>: Send + 'static {
fn call_box(self: Box<Self>) -> SyncAddress<A>;
}
impl<A: Actor, F: FnOnce() -> SyncAddress<A> + Send + 'static> FnBox<A> for F {
#[cfg_attr(feature="cargo-clippy", allow(boxed_local))]
fn call_box(self: Box<Self>) -> SyncAddress<A> {
(*self)()
}
}
pub struct Execute<I: Send + 'static = (), E: Send + 'static = ()>(Box<FnExec<I, E>>);
impl<I: Send, E: Send> ResponseType for Execute<I, E> {
type Item = I;
type Error = E;
}
impl<I, E> Execute<I, E>
where I: Send + 'static, E: Send + 'static
{
pub fn new<F>(f: F) -> Self where F: FnOnce() -> Result<I, E> + Send + 'static
{
Execute(Box::new(f))
}
pub fn exec(self) -> Result<I, E> {
self.0.call_box()
}
}
trait FnExec<I: Send + 'static, E: Send + 'static>: Send + 'static {
fn call_box(self: Box<Self>) -> Result<I, E>;
}
impl<I, E, F> FnExec<I, E> for F
where I: Send + 'static,
E: Send + 'static,
F: FnOnce() -> Result<I, E> + Send + 'static
{
#[cfg_attr(feature="cargo-clippy", allow(boxed_local))]
fn call_box(self: Box<Self>) -> Result<I, E> {
(*self)()
}
}