diff options
| author | Mica White <botahamec@gmail.com> | 2024-12-23 15:31:07 -0500 |
|---|---|---|
| committer | Mica White <botahamec@gmail.com> | 2024-12-23 15:33:02 -0500 |
| commit | 30d0f08b6073e9c2e545a3567838a9e1e885fea2 (patch) | |
| tree | 5763e820ed5877b39ef9745e2a9380e665ced099 /src/poisonable/error.rs | |
| parent | fa4fe582f212bec3e4d9fe288aaac8c471b8e987 (diff) | |
Remove scopeguard
The scopeguard crate was being used for its `defer_on_unwind` macro.
The problem was that it runs even if the runtime was already panicking.
There aren't any changes to the macro which could have fixed this.
I instead wrote my own function to check for a specific panicking closure.
Diffstat (limited to 'src/poisonable/error.rs')
| -rw-r--r-- | src/poisonable/error.rs | 12 |
1 files changed, 4 insertions, 8 deletions
diff --git a/src/poisonable/error.rs b/src/poisonable/error.rs index 9e84693..f27c6ab 100644 --- a/src/poisonable/error.rs +++ b/src/poisonable/error.rs @@ -1,6 +1,5 @@ use core::fmt; use std::error::Error; -use std::ops::{Deref, DerefMut}; use super::{PoisonError, PoisonGuard, TryLockPoisonableError}; @@ -68,9 +67,7 @@ impl<Guard> PoisonError<Guard> { pub fn into_inner(self) -> Guard { self.guard } -} -impl<T, Guard: Deref<Target = T>> PoisonError<Guard> { /// Reaches into this error indicating that a lock is poisoned, returning a /// reference to the underlying guard to allow access regardless. /// @@ -82,6 +79,7 @@ impl<T, Guard: Deref<Target = T>> PoisonError<Guard> { /// use std::thread; /// /// use happylock::{Mutex, Poisonable, ThreadKey}; + /// use happylock::poisonable::PoisonGuard; /// /// let mutex = Arc::new(Poisonable::new(Mutex::new(HashSet::new()))); /// @@ -96,16 +94,14 @@ impl<T, Guard: Deref<Target = T>> PoisonError<Guard> { /// /// let key = ThreadKey::get().unwrap(); /// let p_err = mutex.lock(key).unwrap_err(); - /// let data = p_err.get_ref(); + /// let data: &PoisonGuard<_, _> = p_err.get_ref(); /// println!("recovered {} items", data.len()); /// ``` #[must_use] - pub fn get_ref(&self) -> &T { + pub const fn get_ref(&self) -> &Guard { &self.guard } -} -impl<T, Guard: DerefMut<Target = T>> PoisonError<Guard> { /// Reaches into this error indicating that a lock is poisoned, returning a /// mutable reference to the underlying guard to allow access regardless. /// @@ -136,7 +132,7 @@ impl<T, Guard: DerefMut<Target = T>> PoisonError<Guard> { /// println!("recovered {} items", data.len()); /// ``` #[must_use] - pub fn get_mut(&mut self) -> &mut T { + pub fn get_mut(&mut self) -> &mut Guard { &mut self.guard } } |
