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
use derive_more::{Display, Error};
#[derive(Debug, Display, Error)]
#[non_exhaustive]
pub enum StartError {
#[display(fmt = "invalid config")]
InvalidConfig,
Other(#[error(not(source))] String),
}
#[derive(Debug, Display, Error)]
#[display(fmt = "mailbox closed")]
pub struct SendError<T>(#[error(not(source))] pub T);
#[derive(Debug, Display, Error)]
pub enum TrySendError<T> {
#[display(fmt = "mailbox full")]
Full(#[error(not(source))] T),
#[display(fmt = "mailbox closed")]
Closed(#[error(not(source))] T),
}
impl<T> TrySendError<T> {
#[inline]
pub fn into_inner(self) -> T {
match self {
Self::Closed(inner) => inner,
Self::Full(inner) => inner,
}
}
#[inline]
pub fn is_full(&self) -> bool {
matches!(self, Self::Full(_))
}
#[inline]
pub fn is_closed(&self) -> bool {
matches!(self, Self::Closed(_))
}
}
#[derive(Debug, Display, Error)]
pub enum RequestError<T> {
#[display(fmt = "request ignored")]
Ignored,
#[display(fmt = "mailbox closed")]
Closed(#[error(not(source))] T),
}
impl<T> RequestError<T> {
#[inline]
pub fn into_inner(self) -> Option<T> {
match self {
Self::Ignored => None,
Self::Closed(inner) => Some(inner),
}
}
#[inline]
pub fn is_ignored(&self) -> bool {
matches!(self, Self::Ignored)
}
#[inline]
pub fn is_closed(&self) -> bool {
matches!(self, Self::Closed(_))
}
}
#[derive(Debug, Clone, Display, Error)]
pub enum TryRecvError {
#[display(fmt = "mailbox empty")]
Empty,
#[display(fmt = "mailbox closed")]
Closed,
}
impl TryRecvError {
#[inline]
pub fn is_empty(&self) -> bool {
matches!(self, Self::Empty)
}
#[inline]
pub fn is_closed(&self) -> bool {
matches!(self, Self::Closed)
}
}