summaryrefslogtreecommitdiffstats
path: root/tokio-sync/src/watch.rs
diff options
context:
space:
mode:
authorThomas Lacroix <toto.rigolo@free.fr>2019-03-12 16:51:23 +0100
committerCarl Lerche <me@carllerche.com>2019-03-12 08:51:23 -0700
commit676824988e12d21878ede2d91b773354b6b0981c (patch)
tree0b62b9e675c2aab1a3734bb2ec3095e231add0d4 /tokio-sync/src/watch.rs
parent46149f031e406e43fe4ca4d0d3f0ad9e036e2768 (diff)
sync: impl `Error` for oneshot and watch error types (#967)
Refs: #937
Diffstat (limited to 'tokio-sync/src/watch.rs')
-rw-r--r--tokio-sync/src/watch.rs32
1 files changed, 32 insertions, 0 deletions
diff --git a/tokio-sync/src/watch.rs b/tokio-sync/src/watch.rs
index 4c2b2972..b3303bdc 100644
--- a/tokio-sync/src/watch.rs
+++ b/tokio-sync/src/watch.rs
@@ -104,6 +104,8 @@ pub struct Ref<'a, T: 'a> {
pub mod error {
//! Watch error types
+ use std::fmt;
+
/// Error produced when receiving a value fails.
#[derive(Debug)]
pub struct RecvError {
@@ -115,6 +117,36 @@ pub mod error {
pub struct SendError<T> {
pub(crate) inner: 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"
+ }
+ }
+
+ // ===== impl SendError =====
+
+ impl<T: fmt::Debug> fmt::Display for SendError<T> {
+ fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
+ use std::error::Error;
+ write!(fmt, "{}", self.description())
+ }
+ }
+
+ impl<T: fmt::Debug> ::std::error::Error for SendError<T> {
+ fn description(&self) -> &str {
+ "channel closed"
+ }
+ }
}
#[derive(Debug)]