From 5753c9b69fe2fe17ae8edd61766128ae158de5ac Mon Sep 17 00:00:00 2001 From: Gil Shoshan Date: Tue, 2 May 2023 12:39:35 +0300 Subject: [PATCH 1/4] Update mpsc::error Update mpsc::error::{SendError, TrySendError, SendTimeoutError} to match the errors from the std lib in their mpsc channel. Removed bond . Add derived impl PartialEq, Eq, Clone and Copy (only if T implement them) --- tokio/src/sync/mpsc/error.rs | 38 +++++++++++++++++++++++++++++------- 1 file changed, 31 insertions(+), 7 deletions(-) diff --git a/tokio/src/sync/mpsc/error.rs b/tokio/src/sync/mpsc/error.rs index 1c789da0cdd..11372b320b7 100644 --- a/tokio/src/sync/mpsc/error.rs +++ b/tokio/src/sync/mpsc/error.rs @@ -4,22 +4,28 @@ use std::error::Error; use std::fmt; /// Error returned by the `Sender`. -#[derive(Debug)] +#[derive(PartialEq, Eq, Clone, Copy)] pub struct SendError(pub T); +impl fmt::Debug for SendError { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_struct("SendError").finish_non_exhaustive() + } +} + impl fmt::Display for SendError { fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { write!(fmt, "channel closed") } } -impl std::error::Error for SendError {} +impl std::error::Error for SendError {} // ===== TrySendError ===== /// This enumeration is the list of the possible error outcomes for the /// [try_send](super::Sender::try_send) method. -#[derive(Debug, Eq, PartialEq)] +#[derive(PartialEq, Eq, Clone, Copy)] pub enum TrySendError { /// The data could not be sent on the channel because the channel is /// currently full and sending would require blocking. @@ -30,7 +36,14 @@ pub enum TrySendError { Closed(T), } -impl Error for TrySendError {} +impl fmt::Debug for TrySendError { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match *self { + TrySendError::Full(..) => "Full(..)".fmt(f), + TrySendError::Closed(..) => "Closed(..)".fmt(f), + } + } +} impl fmt::Display for TrySendError { fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { @@ -45,6 +58,8 @@ impl fmt::Display for TrySendError { } } +impl Error for TrySendError {} + impl From> for TrySendError { fn from(src: SendError) -> TrySendError { TrySendError::Closed(src.0) @@ -96,7 +111,7 @@ impl Error for RecvError {} cfg_time! { // ===== SendTimeoutError ===== - #[derive(Debug, Eq, PartialEq)] + #[derive(PartialEq, Eq, Clone, Copy)] /// Error returned by [`Sender::send_timeout`](super::Sender::send_timeout)]. pub enum SendTimeoutError { /// The data could not be sent on the channel because the channel is @@ -107,8 +122,15 @@ cfg_time! { /// dropped. Closed(T), } - - impl Error for SendTimeoutError {} + + impl fmt::Debug for SendTimeoutError { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match *self { + SendTimeoutError::Timeout(..) => "Timeout(..)".fmt(f), + SendTimeoutError::Closed(..) => "Closed(..)".fmt(f), + } + } + } impl fmt::Display for SendTimeoutError { fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { @@ -122,4 +144,6 @@ cfg_time! { ) } } + + impl Error for SendTimeoutError {} } From c452bdb4aadf3a78c73e0eecc8e5544106bb6bd8 Mon Sep 17 00:00:00 2001 From: Gil Shoshan Date: Tue, 2 May 2023 12:49:09 +0300 Subject: [PATCH 2/4] Update watch::error Update watch::error::SendError to match the error from the std lib in their mpsc channel (also a SendError). Removed bond . Add derived impl PartialEq, Eq, Clone and Copy (only if T implement them) --- tokio/src/sync/watch.rs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/tokio/src/sync/watch.rs b/tokio/src/sync/watch.rs index 449711ad75c..8468c0e9921 100644 --- a/tokio/src/sync/watch.rs +++ b/tokio/src/sync/watch.rs @@ -208,18 +208,24 @@ pub mod error { use std::fmt; /// Error produced when sending a value fails. - #[derive(Debug)] + #[derive(PartialEq, Eq, Clone, Copy)] pub struct SendError(pub T); // ===== impl SendError ===== - - impl fmt::Display for SendError { + + impl fmt::Debug for SendError { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_struct("SendError").finish_non_exhaustive() + } + } + + impl fmt::Display for SendError { fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { write!(fmt, "channel closed") } } - impl std::error::Error for SendError {} + impl std::error::Error for SendError {} /// Error produced when receiving a change notification. #[derive(Debug, Clone)] From ed1bdf7b6c8e89ab7d4607f28759d71e9ef89da4 Mon Sep 17 00:00:00 2001 From: Gil Shoshan Date: Tue, 2 May 2023 13:38:01 +0300 Subject: [PATCH 3/4] fmt fix - removed whitespaces --- tokio/src/sync/mpsc/error.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tokio/src/sync/mpsc/error.rs b/tokio/src/sync/mpsc/error.rs index 11372b320b7..25b4455bee7 100644 --- a/tokio/src/sync/mpsc/error.rs +++ b/tokio/src/sync/mpsc/error.rs @@ -122,7 +122,7 @@ cfg_time! { /// dropped. Closed(T), } - + impl fmt::Debug for SendTimeoutError { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match *self { @@ -144,6 +144,6 @@ cfg_time! { ) } } - + impl Error for SendTimeoutError {} } From be71e7e90d60a471094e835156f432d88fdeb8f1 Mon Sep 17 00:00:00 2001 From: Gil Shoshan Date: Tue, 2 May 2023 13:40:39 +0300 Subject: [PATCH 4/4] fmt fix - removed whitespaces --- tokio/src/sync/watch.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tokio/src/sync/watch.rs b/tokio/src/sync/watch.rs index 8468c0e9921..8213da6dea4 100644 --- a/tokio/src/sync/watch.rs +++ b/tokio/src/sync/watch.rs @@ -212,13 +212,13 @@ pub mod error { pub struct SendError(pub T); // ===== impl SendError ===== - + impl fmt::Debug for SendError { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("SendError").finish_non_exhaustive() } } - + impl fmt::Display for SendError { fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { write!(fmt, "channel closed")