broker_tokio/sync/mpsc/
error.rs1use std::error::Error;
4use std::fmt;
5
6#[derive(Debug)]
8pub struct SendError<T>(pub T);
9
10impl<T> fmt::Display for SendError<T> {
11 fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
12 write!(fmt, "channel closed")
13 }
14}
15
16impl<T: fmt::Debug> std::error::Error for SendError<T> {}
17
18#[derive(Debug)]
23pub enum TrySendError<T> {
24 Full(T),
27
28 Closed(T),
31}
32
33impl<T: fmt::Debug> Error for TrySendError<T> {}
34
35impl<T> fmt::Display for TrySendError<T> {
36 fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
37 write!(
38 fmt,
39 "{}",
40 match self {
41 TrySendError::Full(..) => "no available capacity",
42 TrySendError::Closed(..) => "channel closed",
43 }
44 )
45 }
46}
47
48impl<T> From<SendError<T>> for TrySendError<T> {
49 fn from(src: SendError<T>) -> TrySendError<T> {
50 TrySendError::Closed(src.0)
51 }
52}
53
54#[derive(Debug)]
58pub struct RecvError(());
59
60impl fmt::Display for RecvError {
61 fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
62 write!(fmt, "channel closed")
63 }
64}
65
66impl Error for RecvError {}
67
68#[derive(Debug, PartialEq)]
73pub enum TryRecvError {
74 Empty,
77 Closed,
80}
81
82impl fmt::Display for TryRecvError {
83 fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
84 write!(
85 fmt,
86 "{}",
87 match self {
88 TryRecvError::Empty => "channel empty",
89 TryRecvError::Closed => "channel closed",
90 }
91 )
92 }
93}
94
95impl Error for TryRecvError {}
96
97#[derive(Debug)]
101pub struct ClosedError(());
102
103impl ClosedError {
104 pub(crate) fn new() -> ClosedError {
105 ClosedError(())
106 }
107}
108
109impl fmt::Display for ClosedError {
110 fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
111 write!(fmt, "channel closed")
112 }
113}
114
115impl Error for ClosedError {}