1pub use crate::sync::mpsc::{RecvError, RecvTimeoutError, SendError, TryRecvError, TrySendError};
2use crate::{error, fmt};
34/// 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")]
11pub 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.
16Timeout(T),
1718/// The message could not be sent because the channel is disconnected.
19Disconnected(T),
20}
2122#[unstable(feature = "mpmc_channel", issue = "126840")]
23impl<T> fmt::Debug for SendTimeoutError<T> {
24fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
25"SendTimeoutError(..)".fmt(f)
26 }
27}
2829#[unstable(feature = "mpmc_channel", issue = "126840")]
30impl<T> fmt::Display for SendTimeoutError<T> {
31fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
32match *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}
3839#[unstable(feature = "mpmc_channel", issue = "126840")]
40impl<T> error::Error for SendTimeoutError<T> {}
4142#[unstable(feature = "mpmc_channel", issue = "126840")]
43impl<T> From<SendError<T>> for SendTimeoutError<T> {
44fn from(err: SendError<T>) -> SendTimeoutError<T> {
45match err {
46 SendError(e) => SendTimeoutError::Disconnected(e),
47 }
48 }
49}