mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-08-27 00:00:12 +02:00
sync: implement more traits for channel errors (#5666)
This commit is contained in:
@@ -4,22 +4,28 @@ use std::error::Error;
|
|||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
|
||||||
/// Error returned by the `Sender`.
|
/// Error returned by the `Sender`.
|
||||||
#[derive(Debug)]
|
#[derive(PartialEq, Eq, Clone, Copy)]
|
||||||
pub struct SendError<T>(pub T);
|
pub struct SendError<T>(pub T);
|
||||||
|
|
||||||
|
impl<T> fmt::Debug for SendError<T> {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
|
f.debug_struct("SendError").finish_non_exhaustive()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<T> fmt::Display for SendError<T> {
|
impl<T> fmt::Display for SendError<T> {
|
||||||
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
write!(fmt, "channel closed")
|
write!(fmt, "channel closed")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: fmt::Debug> std::error::Error for SendError<T> {}
|
impl<T> std::error::Error for SendError<T> {}
|
||||||
|
|
||||||
// ===== TrySendError =====
|
// ===== TrySendError =====
|
||||||
|
|
||||||
/// This enumeration is the list of the possible error outcomes for the
|
/// This enumeration is the list of the possible error outcomes for the
|
||||||
/// [try_send](super::Sender::try_send) method.
|
/// [try_send](super::Sender::try_send) method.
|
||||||
#[derive(Debug, Eq, PartialEq)]
|
#[derive(PartialEq, Eq, Clone, Copy)]
|
||||||
pub enum TrySendError<T> {
|
pub enum TrySendError<T> {
|
||||||
/// The data could not be sent on the channel because the channel is
|
/// The data could not be sent on the channel because the channel is
|
||||||
/// currently full and sending would require blocking.
|
/// currently full and sending would require blocking.
|
||||||
@@ -30,7 +36,14 @@ pub enum TrySendError<T> {
|
|||||||
Closed(T),
|
Closed(T),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: fmt::Debug> Error for TrySendError<T> {}
|
impl<T> fmt::Debug for TrySendError<T> {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
|
match *self {
|
||||||
|
TrySendError::Full(..) => "Full(..)".fmt(f),
|
||||||
|
TrySendError::Closed(..) => "Closed(..)".fmt(f),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<T> fmt::Display for TrySendError<T> {
|
impl<T> fmt::Display for TrySendError<T> {
|
||||||
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
@@ -45,6 +58,8 @@ impl<T> fmt::Display for TrySendError<T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<T> Error for TrySendError<T> {}
|
||||||
|
|
||||||
impl<T> From<SendError<T>> for TrySendError<T> {
|
impl<T> From<SendError<T>> for TrySendError<T> {
|
||||||
fn from(src: SendError<T>) -> TrySendError<T> {
|
fn from(src: SendError<T>) -> TrySendError<T> {
|
||||||
TrySendError::Closed(src.0)
|
TrySendError::Closed(src.0)
|
||||||
@@ -96,7 +111,7 @@ impl Error for RecvError {}
|
|||||||
cfg_time! {
|
cfg_time! {
|
||||||
// ===== SendTimeoutError =====
|
// ===== SendTimeoutError =====
|
||||||
|
|
||||||
#[derive(Debug, Eq, PartialEq)]
|
#[derive(PartialEq, Eq, Clone, Copy)]
|
||||||
/// Error returned by [`Sender::send_timeout`](super::Sender::send_timeout)].
|
/// Error returned by [`Sender::send_timeout`](super::Sender::send_timeout)].
|
||||||
pub enum SendTimeoutError<T> {
|
pub enum SendTimeoutError<T> {
|
||||||
/// The data could not be sent on the channel because the channel is
|
/// The data could not be sent on the channel because the channel is
|
||||||
@@ -108,7 +123,14 @@ cfg_time! {
|
|||||||
Closed(T),
|
Closed(T),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: fmt::Debug> Error for SendTimeoutError<T> {}
|
impl<T> fmt::Debug for SendTimeoutError<T> {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
|
match *self {
|
||||||
|
SendTimeoutError::Timeout(..) => "Timeout(..)".fmt(f),
|
||||||
|
SendTimeoutError::Closed(..) => "Closed(..)".fmt(f),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<T> fmt::Display for SendTimeoutError<T> {
|
impl<T> fmt::Display for SendTimeoutError<T> {
|
||||||
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
@@ -122,4 +144,6 @@ cfg_time! {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<T> Error for SendTimeoutError<T> {}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -208,18 +208,24 @@ pub mod error {
|
|||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
|
||||||
/// Error produced when sending a value fails.
|
/// Error produced when sending a value fails.
|
||||||
#[derive(Debug)]
|
#[derive(PartialEq, Eq, Clone, Copy)]
|
||||||
pub struct SendError<T>(pub T);
|
pub struct SendError<T>(pub T);
|
||||||
|
|
||||||
// ===== impl SendError =====
|
// ===== impl SendError =====
|
||||||
|
|
||||||
impl<T: fmt::Debug> fmt::Display for SendError<T> {
|
impl<T> fmt::Debug for SendError<T> {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
|
f.debug_struct("SendError").finish_non_exhaustive()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T> fmt::Display for SendError<T> {
|
||||||
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
write!(fmt, "channel closed")
|
write!(fmt, "channel closed")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: fmt::Debug> std::error::Error for SendError<T> {}
|
impl<T> std::error::Error for SendError<T> {}
|
||||||
|
|
||||||
/// Error produced when receiving a change notification.
|
/// Error produced when receiving a change notification.
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
|
|||||||
Reference in New Issue
Block a user