1 | use crate::error; |
2 | use crate::fmt; |
3 | |
4 | pub use crate::sync::mpsc::{RecvError, RecvTimeoutError, SendError, TryRecvError, TrySendError}; |
5 | |
6 | /// An error returned from the [`send_timeout`] method. |
7 | /// |
8 | /// The error contains the message being sent so it can be recovered. |
9 | /// |
10 | /// [`send_timeout`]: super::Sender::send_timeout |
11 | #[derive (PartialEq, Eq, Clone, Copy)] |
12 | pub enum SendTimeoutError<T> { |
13 | /// The message could not be sent because the channel is full and the operation timed out. |
14 | /// |
15 | /// If this is a zero-capacity channel, then the error indicates that there was no receiver |
16 | /// available to receive the message and the operation timed out. |
17 | Timeout(T), |
18 | |
19 | /// The message could not be sent because the channel is disconnected. |
20 | Disconnected(T), |
21 | } |
22 | |
23 | impl<T> fmt::Debug for SendTimeoutError<T> { |
24 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
25 | "SendTimeoutError(..)" .fmt(f) |
26 | } |
27 | } |
28 | |
29 | impl<T> fmt::Display for SendTimeoutError<T> { |
30 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
31 | match *self { |
32 | SendTimeoutError::Timeout(..) => "timed out waiting on send operation" .fmt(f), |
33 | SendTimeoutError::Disconnected(..) => "sending on a disconnected channel" .fmt(f), |
34 | } |
35 | } |
36 | } |
37 | |
38 | impl<T> error::Error for SendTimeoutError<T> {} |
39 | |
40 | impl<T> From<SendError<T>> for SendTimeoutError<T> { |
41 | fn from(err: SendError<T>) -> SendTimeoutError<T> { |
42 | match err { |
43 | SendError(e: T) => SendTimeoutError::Disconnected(e), |
44 | } |
45 | } |
46 | } |
47 | |