1#[derive(Copy, Clone, Debug, thiserror::Error)]
8pub enum Error {
9 #[error("operation would block")]
11 WouldBlock,
12 #[error("connection terminated")]
14 Disconnected,
15 #[error("facility already seized")]
17 Occupied,
18}
19
20#[derive(Debug, thiserror::Error)]
24#[error("no receiver left")]
25pub struct SendError<T>(pub T);
26
27impl<T> From<SendError<T>> for Error {
28 #[inline]
29 fn from(_: SendError<T>) -> Self {
30 Error::Disconnected
31 }
32}
33
34#[derive(Debug, thiserror::Error)]
36#[error("no sender left")]
37pub struct RecvError;
38
39impl From<RecvError> for Error {
40 #[inline]
41 fn from(_: RecvError) -> Self {
42 Error::Disconnected
43 }
44}
45
46#[derive(Debug, thiserror::Error)]
50pub enum TrySendError<T> {
51 #[error("channel buffer is full")]
53 Full(T),
54 #[error("channel disconnected")]
56 Disconnected(T),
57}
58
59impl<T> From<TrySendError<T>> for Error {
60 #[inline]
61 fn from(err: TrySendError<T>) -> Self {
62 match err {
63 TrySendError::Full(_) => Error::WouldBlock,
64 TrySendError::Disconnected(_) => Error::Disconnected,
65 }
66 }
67}
68
69#[derive(Debug, thiserror::Error)]
73pub enum TryRecvError {
74 #[error("channel buffer is empty")]
76 Empty,
77 #[error("channel disconnected")]
79 Disconnected,
80}
81
82impl From<TryRecvError> for Error {
83 #[inline]
84 fn from(err: TryRecvError) -> Self {
85 match err {
86 TryRecvError::Empty => Error::WouldBlock,
87 TryRecvError::Disconnected => Error::Disconnected,
88 }
89 }
90}
91
92#[derive(Debug, thiserror::Error)]
94#[error("facility already seized")]
95pub struct FacilityOccupied;
96
97impl From<FacilityOccupied> for Error {
98 #[inline]
99 fn from(_: FacilityOccupied) -> Self {
100 Error::Occupied
101 }
102}