|
11 | 11 | use prelude::v1::*;
|
12 | 12 |
|
13 | 13 | use cell::UnsafeCell;
|
14 |
| -use error::FromError; |
| 14 | +use error::{Error, FromError}; |
15 | 15 | use fmt;
|
16 | 16 | use thread::Thread;
|
17 | 17 |
|
@@ -92,7 +92,13 @@ pub type TryLockResult<Guard> = Result<Guard, TryLockError<Guard>>;
|
92 | 92 |
|
93 | 93 | impl<T> fmt::Show for PoisonError<T> {
|
94 | 94 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
95 |
| - "poisoned lock: another task failed inside".fmt(f) |
| 95 | + self.description().fmt(f) |
| 96 | + } |
| 97 | +} |
| 98 | + |
| 99 | +impl<T> Error for PoisonError<T> { |
| 100 | + fn description(&self) -> &str { |
| 101 | + "poisoned lock: another task failed inside" |
96 | 102 | }
|
97 | 103 | }
|
98 | 104 |
|
@@ -126,11 +132,22 @@ impl<T> FromError<PoisonError<T>> for TryLockError<T> {
|
126 | 132 |
|
127 | 133 | impl<T> fmt::Show for TryLockError<T> {
|
128 | 134 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
| 135 | + self.description().fmt(f) |
| 136 | + } |
| 137 | +} |
| 138 | + |
| 139 | +impl<T> Error for TryLockError<T> { |
| 140 | + fn description(&self) -> &str { |
| 141 | + match *self { |
| 142 | + TryLockError::Poisoned(ref p) => p.description(), |
| 143 | + TryLockError::WouldBlock => "try_lock failed because the operation would block" |
| 144 | + } |
| 145 | + } |
| 146 | + |
| 147 | + fn cause(&self) -> Option<&Error> { |
129 | 148 | match *self {
|
130 |
| - TryLockError::Poisoned(ref p) => p.fmt(f), |
131 |
| - TryLockError::WouldBlock => { |
132 |
| - "try_lock failed because the operation would block".fmt(f) |
133 |
| - } |
| 149 | + TryLockError::Poisoned(ref p) => Some(p), |
| 150 | + _ => None |
134 | 151 | }
|
135 | 152 | }
|
136 | 153 | }
|
|
0 commit comments