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