diff --git a/tokio-sync/src/mpsc/bounded.rs b/tokio-sync/src/mpsc/bounded.rs index 0260c95ab..de65dd55c 100644 --- a/tokio-sync/src/mpsc/bounded.rs +++ b/tokio-sync/src/mpsc/bounded.rs @@ -284,3 +284,18 @@ impl From<(T, chan::TrySendError)> for TrySendError { } } } + +// ===== 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" + } +} diff --git a/tokio-sync/src/mpsc/unbounded.rs b/tokio-sync/src/mpsc/unbounded.rs index 67e61fdb6..3caa4b5d5 100644 --- a/tokio-sync/src/mpsc/unbounded.rs +++ b/tokio-sync/src/mpsc/unbounded.rs @@ -180,3 +180,18 @@ impl From<(T, chan::TrySendError)> for UnboundedTrySendError { 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" + } +} diff --git a/tokio-sync/tests/errors.rs b/tokio-sync/tests/errors.rs new file mode 100644 index 000000000..0e56cc1ab --- /dev/null +++ b/tokio-sync/tests/errors.rs @@ -0,0 +1,17 @@ +#![deny(warnings)] + +extern crate tokio_sync; + +use tokio_sync::mpsc::error; + +fn is_error() {} + +#[test] +fn error_bound() { + is_error::(); + is_error::(); + is_error::>(); + is_error::(); + is_error::(); + is_error::>(); +}