1#![forbid(unsafe_code)]
19#![deny(missing_docs)]
20
21use std::sync::{
22 LockResult, MutexGuard, PoisonError, RwLockReadGuard, RwLockWriteGuard,
23};
24
25pub trait OrPoisoned {
27 type Inner;
29
30 fn or_poisoned(self) -> Self::Inner;
36}
37
38impl<'a, T> OrPoisoned
39 for Result<RwLockReadGuard<'a, T>, PoisonError<RwLockReadGuard<'a, T>>>
40{
41 type Inner = RwLockReadGuard<'a, T>;
42
43 fn or_poisoned(self) -> Self::Inner {
44 self.expect("lock poisoned")
45 }
46}
47
48impl<'a, T> OrPoisoned
49 for Result<RwLockWriteGuard<'a, T>, PoisonError<RwLockWriteGuard<'a, T>>>
50{
51 type Inner = RwLockWriteGuard<'a, T>;
52
53 fn or_poisoned(self) -> Self::Inner {
54 self.expect("lock poisoned")
55 }
56}
57
58impl<'a, T> OrPoisoned for LockResult<MutexGuard<'a, T>> {
59 type Inner = MutexGuard<'a, T>;
60
61 fn or_poisoned(self) -> Self::Inner {
62 self.expect("lock poisoned")
63 }
64}