sync::oneshot::{Try,}{Send,Recv}Error{<T>,}: Added send + recv + generic error (with consuming variants for re-triable operations.)

Fortune for reverse's current commit: Small blessing − 小吉
refactor
Avril 3 weeks ago
parent bea2631fb7
commit 491867fbbb
Signed by: flanchan
GPG Key ID: 284488987C31F630

@ -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<T>` 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<T>` 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[<T>]...
impl<T> fmt::Display for TrySendError<T>
{
#[inline]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result
{
write!(f, "send error (T = {})", std::any::type_name::<T>())
}
}
impl<T> fmt::Display for TryRecvError<T>
{
#[inline]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result
{
write!(f, "recv error (T = {})", std::any::type_name::<T>())
}
}
impl<T> error::Error for TryRecvError<T>
where T: fmt::Debug
{
#[inline]
fn source(&self) -> Option<&(dyn error::Error + 'static)> {
Some(&self.0)
}
}
impl<T> error::Error for TrySendError<T>
where T: fmt::Debug
{
#[inline]
fn source(&self) -> Option<&(dyn error::Error + 'static)> {
Some(&self.0)
}
}
impl<T> fmt::Display for TryError<T>
{
#[inline]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result
{
write!(f, "oneshot error (T = {})", std::any::type_name::<T>())
}
}
impl<T> error::Error for TryError<T>
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<T>`s, since `T` is irrelevent to the `Error` part.
/// Error when attempting to send a value using a `try_` function.

Loading…
Cancel
Save