about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorEduard-Mihai Burtescu <edy.burt@gmail.com>2016-11-12 10:38:37 +0200
committerGitHub <noreply@github.com>2016-11-12 10:38:37 +0200
commit29195e26d28f19c8f2629ce320dd9792dc6b27b6 (patch)
tree148c0d284c92a66e46df9dcf3bc6cb5640f8ab61 /src/libstd
parent16ae078fe994535f3b362c6af0389549b6516063 (diff)
parent2af61112d4cbe1b0a7ae4afd99ef387002b7a7de (diff)
downloadrust-29195e26d28f19c8f2629ce320dd9792dc6b27b6.tar.gz
rust-29195e26d28f19c8f2629ce320dd9792dc6b27b6.zip
Rollup merge of #37527 - Mark-Simulacrum:mpsc-recvtimeouterror-error-impl, r=alexcrichton
Add Error implementation for std::sync::mpsc::RecvTimeoutError.

Fixes https://github.com/rust-lang/rust/issues/37525.
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/sync/mpsc/mod.rs32
1 files changed, 32 insertions, 0 deletions
diff --git a/src/libstd/sync/mpsc/mod.rs b/src/libstd/sync/mpsc/mod.rs
index fce640e7c7a..2773629c7d7 100644
--- a/src/libstd/sync/mpsc/mod.rs
+++ b/src/libstd/sync/mpsc/mod.rs
@@ -1267,6 +1267,38 @@ impl error::Error for TryRecvError {
     }
 }
 
+#[stable(feature = "mpsc_recv_timeout_error", since = "1.14.0")]
+impl fmt::Display for RecvTimeoutError {
+    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+        match *self {
+            RecvTimeoutError::Timeout => {
+                "timed out waiting on channel".fmt(f)
+            }
+            RecvTimeoutError::Disconnected => {
+                "channel is empty and sending half is closed".fmt(f)
+            }
+        }
+    }
+}
+
+#[stable(feature = "mpsc_recv_timeout_error", since = "1.14.0")]
+impl error::Error for RecvTimeoutError {
+    fn description(&self) -> &str {
+        match *self {
+            RecvTimeoutError::Timeout => {
+                "timed out waiting on channel"
+            }
+            RecvTimeoutError::Disconnected => {
+                "channel is empty and sending half is closed"
+            }
+        }
+    }
+
+    fn cause(&self) -> Option<&error::Error> {
+        None
+    }
+}
+
 #[cfg(all(test, not(target_os = "emscripten")))]
 mod tests {
     use env;