about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorMichael Sproul <micsproul@gmail.com>2015-01-17 11:31:55 -0800
committerMichael Sproul <micsproul@gmail.com>2015-01-17 14:35:16 -0800
commitffdf1118d5f86b4d55cbf8ec86aa488d9dfc88b2 (patch)
tree2db64ca102e35eb65cb33986e2fd7849b7275c06 /src/libstd
parentf4f10dba2975b51c2d2c92157018db3ac13d4d4a (diff)
downloadrust-ffdf1118d5f86b4d55cbf8ec86aa488d9dfc88b2.tar.gz
rust-ffdf1118d5f86b4d55cbf8ec86aa488d9dfc88b2.zip
Implement the error trait for errors in std::sync.
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/sync/poison.rs29
1 files changed, 23 insertions, 6 deletions
diff --git a/src/libstd/sync/poison.rs b/src/libstd/sync/poison.rs
index cc8c331ef39..e28c3c37b6f 100644
--- a/src/libstd/sync/poison.rs
+++ b/src/libstd/sync/poison.rs
@@ -11,7 +11,7 @@
 use prelude::v1::*;
 
 use cell::UnsafeCell;
-use error::FromError;
+use error::{Error, FromError};
 use fmt;
 use thread::Thread;
 
@@ -92,7 +92,13 @@ pub type TryLockResult<Guard> = Result<Guard, TryLockError<Guard>>;
 
 impl<T> fmt::Show for PoisonError<T> {
     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
-        "poisoned lock: another task failed inside".fmt(f)
+        self.description().fmt(f)
+    }
+}
+
+impl<T> Error for PoisonError<T> {
+    fn description(&self) -> &str {
+        "poisoned lock: another task failed inside"
     }
 }
 
@@ -126,11 +132,22 @@ impl<T> FromError<PoisonError<T>> for TryLockError<T> {
 
 impl<T> fmt::Show for TryLockError<T> {
     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+        self.description().fmt(f)
+    }
+}
+
+impl<T> Error for TryLockError<T> {
+    fn description(&self) -> &str {
+        match *self {
+            TryLockError::Poisoned(ref p) => p.description(),
+            TryLockError::WouldBlock => "try_lock failed because the operation would block"
+        }
+    }
+
+    fn cause(&self) -> Option<&Error> {
         match *self {
-            TryLockError::Poisoned(ref p) => p.fmt(f),
-            TryLockError::WouldBlock => {
-                "try_lock failed because the operation would block".fmt(f)
-            }
+            TryLockError::Poisoned(ref p) => Some(p),
+            _ => None
         }
     }
 }