1use derive_more::{Display, Error};
2
3#[derive(Debug, Display, Error)]
4#[non_exhaustive]
5pub enum StartError {
6 #[display(fmt = "invalid config")]
8 InvalidConfig,
9 Other(#[error(not(source))] String),
10}
11
12#[derive(Debug, Display, Error)]
13#[display(fmt = "mailbox closed")]
14pub struct SendError<T>(#[error(not(source))] pub T);
15
16#[derive(Debug, Display, Error)]
17pub enum TrySendError<T> {
18 #[display(fmt = "mailbox full")]
20 Full(#[error(not(source))] T),
21 #[display(fmt = "mailbox closed")]
23 Closed(#[error(not(source))] T),
24}
25
26impl<T> TrySendError<T> {
27 #[inline]
29 pub fn into_inner(self) -> T {
30 match self {
31 Self::Closed(inner) => inner,
32 Self::Full(inner) => inner,
33 }
34 }
35
36 #[inline]
38 pub fn map<U>(self, f: impl FnOnce(T) -> U) -> TrySendError<U> {
39 match self {
40 Self::Full(inner) => TrySendError::Full(f(inner)),
41 Self::Closed(inner) => TrySendError::Closed(f(inner)),
42 }
43 }
44
45 #[inline]
47 pub fn is_full(&self) -> bool {
48 matches!(self, Self::Full(_))
49 }
50
51 #[inline]
53 pub fn is_closed(&self) -> bool {
54 matches!(self, Self::Closed(_))
55 }
56}
57
58#[derive(Debug, Display, Error)]
59pub enum RequestError<T> {
60 #[display(fmt = "request ignored")]
62 Ignored, #[display(fmt = "mailbox closed")]
65 Closed(#[error(not(source))] T),
66}
67
68impl<T> RequestError<T> {
69 #[inline]
71 pub fn into_inner(self) -> Option<T> {
72 match self {
73 Self::Ignored => None,
74 Self::Closed(inner) => Some(inner),
75 }
76 }
77
78 #[inline]
80 pub fn map<U>(self, f: impl FnOnce(T) -> U) -> RequestError<U> {
81 match self {
82 Self::Ignored => RequestError::Ignored,
83 Self::Closed(inner) => RequestError::Closed(f(inner)),
84 }
85 }
86
87 #[inline]
89 pub fn is_ignored(&self) -> bool {
90 matches!(self, Self::Ignored)
91 }
92
93 #[inline]
95 pub fn is_closed(&self) -> bool {
96 matches!(self, Self::Closed(_))
97 }
98}
99
100#[derive(Debug, Clone, Display, Error)]
101pub enum TryRecvError {
102 #[display(fmt = "mailbox empty")]
104 Empty,
105 #[display(fmt = "mailbox closed")]
107 Closed,
108}
109
110impl TryRecvError {
111 #[inline]
113 pub fn is_empty(&self) -> bool {
114 matches!(self, Self::Empty)
115 }
116
117 #[inline]
119 pub fn is_closed(&self) -> bool {
120 matches!(self, Self::Closed)
121 }
122}