From 30d0f08b6073e9c2e545a3567838a9e1e885fea2 Mon Sep 17 00:00:00 2001 From: Mica White Date: Mon, 23 Dec 2024 15:31:07 -0500 Subject: 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. --- src/poisonable/error.rs | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) (limited to 'src/poisonable/error.rs') 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 PoisonError { pub fn into_inner(self) -> Guard { self.guard } -} -impl> PoisonError { /// 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> PoisonError { /// 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> PoisonError { /// /// 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> PoisonError { /// 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> PoisonError { /// 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 } } -- cgit v1.2.3