diff --git a/src/sync/mod.rs b/src/sync/mod.rs index d023457..ba74bb9 100644 --- a/src/sync/mod.rs +++ b/src/sync/mod.rs @@ -58,19 +58,25 @@ pub mod oneshot { Cancelled, } + //TODO: Add impl Send/RecvError: `fn can_retry(&self) -> bool` + impl fmt::Display for SendError { + #[inline(always)] fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - todo!("`Sender` Error message") + f.write_str("send error") + // TODO: Should we `match self` for detailed error messages here? } } impl fmt::Display for RecvError { + #[inline(always)] fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - todo!("`Receiver` Error message") + f.write_str("recv error") + // TODO: Should we `match self` for detailed error messages here? } } @@ -93,10 +99,7 @@ pub mod oneshot { #[inline(always)] fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - match self { - Self::Recv(_) => f.write_str("recv error"), - Self::Send(_) => f.write_str("send error"), - } + f.write_str("oneshot error") } } @@ -129,6 +132,55 @@ pub mod oneshot { } //TODO: impl fmt::Display error::Error for Try*Error[]... + impl fmt::Display for TrySendError + { + #[inline] + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result + { + write!(f, "send error (T = {})", std::any::type_name::()) + } + } + impl fmt::Display for TryRecvError + { + #[inline] + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result + { + write!(f, "recv error (T = {})", std::any::type_name::()) + } + } + impl error::Error for TryRecvError + where T: fmt::Debug + { + #[inline] + fn source(&self) -> Option<&(dyn error::Error + 'static)> { + Some(&self.0) + } + } + impl error::Error for TrySendError + where T: fmt::Debug + { + #[inline] + fn source(&self) -> Option<&(dyn error::Error + 'static)> { + Some(&self.0) + } + } + impl fmt::Display for TryError + { + #[inline] + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result + { + write!(f, "oneshot error (T = {})", std::any::type_name::()) + } + } + impl error::Error for TryError + where T: fmt::Debug + { + #[inline] + fn source(&self) -> Option<&(dyn error::Error + 'static)> { + Some(&self.0) + } + } + //TODO: XXX: We might also want explicit `Debug` impls for all `Try*Error`s, since `T` is irrelevent to the `Error` part. /// Error when attempting to send a value using a `try_` function.