2022-10-17 19:09:54 -04:00
|
|
|
pub use crate::sync::mpsc::{RecvError, RecvTimeoutError, SendError, TryRecvError, TrySendError};
|
|
|
|
|
use crate::{error, fmt};
|
|
|
|
|
|
|
|
|
|
/// An error returned from the [`send_timeout`] method.
|
|
|
|
|
///
|
|
|
|
|
/// The error contains the message being sent so it can be recovered.
|
|
|
|
|
///
|
|
|
|
|
/// [`send_timeout`]: super::Sender::send_timeout
|
|
|
|
|
#[derive(PartialEq, Eq, Clone, Copy)]
|
2024-06-22 22:17:57 +03:00
|
|
|
#[unstable(feature = "mpmc_channel", issue = "126840")]
|
2022-10-17 19:09:54 -04:00
|
|
|
pub enum SendTimeoutError<T> {
|
|
|
|
|
/// The message could not be sent because the channel is full and the operation timed out.
|
|
|
|
|
///
|
|
|
|
|
/// If this is a zero-capacity channel, then the error indicates that there was no receiver
|
|
|
|
|
/// available to receive the message and the operation timed out.
|
|
|
|
|
Timeout(T),
|
|
|
|
|
|
|
|
|
|
/// The message could not be sent because the channel is disconnected.
|
|
|
|
|
Disconnected(T),
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-22 22:17:57 +03:00
|
|
|
#[unstable(feature = "mpmc_channel", issue = "126840")]
|
2022-10-17 19:09:54 -04:00
|
|
|
impl<T> fmt::Debug for SendTimeoutError<T> {
|
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
|
|
|
"SendTimeoutError(..)".fmt(f)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-22 22:17:57 +03:00
|
|
|
#[unstable(feature = "mpmc_channel", issue = "126840")]
|
2022-10-17 19:09:54 -04:00
|
|
|
impl<T> fmt::Display for SendTimeoutError<T> {
|
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
|
|
|
match *self {
|
|
|
|
|
SendTimeoutError::Timeout(..) => "timed out waiting on send operation".fmt(f),
|
|
|
|
|
SendTimeoutError::Disconnected(..) => "sending on a disconnected channel".fmt(f),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-22 22:17:57 +03:00
|
|
|
#[unstable(feature = "mpmc_channel", issue = "126840")]
|
2023-05-03 15:47:11 +03:00
|
|
|
impl<T> error::Error for SendTimeoutError<T> {}
|
2022-10-17 19:09:54 -04:00
|
|
|
|
2024-06-22 22:17:57 +03:00
|
|
|
#[unstable(feature = "mpmc_channel", issue = "126840")]
|
2022-10-17 19:09:54 -04:00
|
|
|
impl<T> From<SendError<T>> for SendTimeoutError<T> {
|
|
|
|
|
fn from(err: SendError<T>) -> SendTimeoutError<T> {
|
|
|
|
|
match err {
|
|
|
|
|
SendError(e) => SendTimeoutError::Disconnected(e),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|