sync: impl Error for mpsc error types (#937)

This commit is contained in:
Carl Lerche
2019-03-01 12:24:17 -08:00
committed by GitHub
parent 5ff6e37c59
commit 619d3b163b
3 changed files with 47 additions and 0 deletions
+15
View File
@@ -284,3 +284,18 @@ impl<T> From<(T, chan::TrySendError)> for TrySendError<T> {
}
}
}
// ===== impl RecvError =====
impl fmt::Display for RecvError {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
use std::error::Error;
write!(fmt, "{}", self.description())
}
}
impl ::std::error::Error for RecvError {
fn description(&self) -> &str {
"channel closed"
}
}
+15
View File
@@ -180,3 +180,18 @@ impl<T> From<(T, chan::TrySendError)> for UnboundedTrySendError<T> {
UnboundedTrySendError(value)
}
}
// ===== impl UnboundedRecvError =====
impl fmt::Display for UnboundedRecvError {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
use std::error::Error;
write!(fmt, "{}", self.description())
}
}
impl ::std::error::Error for UnboundedRecvError {
fn description(&self) -> &str {
"channel closed"
}
}
+17
View File
@@ -0,0 +1,17 @@
#![deny(warnings)]
extern crate tokio_sync;
use tokio_sync::mpsc::error;
fn is_error<T: ::std::error::Error + Send + Sync>() {}
#[test]
fn error_bound() {
is_error::<error::RecvError>();
is_error::<error::SendError>();
is_error::<error::TrySendError<()>>();
is_error::<error::UnboundedRecvError>();
is_error::<error::UnboundedSendError>();
is_error::<error::UnboundedTrySendError<()>>();
}