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
#[macro_export]
macro_rules! try_ready {
($e:expr) => (match $e {
Ok($crate::Async::Ready(t)) => t,
Ok($crate::Async::NotReady) => return Ok($crate::Async::NotReady),
Err(e) => return Err(From::from(e)),
})
}
pub type Poll<T, E> = Result<Async<T>, E>;
#[derive(Copy, Clone, Debug, PartialEq)]
pub enum Async<T> {
Ready(T),
NotReady,
}
impl<T> Async<T> {
pub fn map<F, U>(self, f: F) -> Async<U>
where F: FnOnce(T) -> U
{
match self {
Async::Ready(t) => Async::Ready(f(t)),
Async::NotReady => Async::NotReady,
}
}
pub fn is_ready(&self) -> bool {
match *self {
Async::Ready(_) => true,
Async::NotReady => false,
}
}
pub fn is_not_ready(&self) -> bool {
!self.is_ready()
}
}
impl<T> From<T> for Async<T> {
fn from(t: T) -> Async<T> {
Async::Ready(t)
}
}
#[derive(Copy, Clone, Debug, PartialEq)]
pub enum AsyncSink<T> {
Ready,
NotReady(T),
}
impl<T> AsyncSink<T> {
pub fn map<F, U>(self, f: F) -> AsyncSink<U>
where F: FnOnce(T) -> U,
{
match self {
AsyncSink::Ready => AsyncSink::Ready,
AsyncSink::NotReady(t) => AsyncSink::NotReady(f(t)),
}
}
pub fn is_ready(&self) -> bool {
match *self {
AsyncSink::Ready => true,
AsyncSink::NotReady(_) => false,
}
}
pub fn is_not_ready(&self) -> bool {
!self.is_ready()
}
}
pub type StartSend<T, E> = Result<AsyncSink<T>, E>;