diff options
| author | Botahamec <botahamec@outlook.com> | 2024-09-26 22:39:09 -0400 |
|---|---|---|
| committer | Botahamec <botahamec@outlook.com> | 2024-09-26 22:39:09 -0400 |
| commit | 5f55113a6ead937fc8bc81e361abc09b3a1565f3 (patch) | |
| tree | a8858abcb05d3796aec89e0fddff5e9ab18a873d /src/poisonable/error.rs | |
| parent | af4013c53e12bfad11bc33c060532320e33729a7 (diff) | |
Reduce the number of dereferences needed
Diffstat (limited to 'src/poisonable/error.rs')
| -rw-r--r-- | src/poisonable/error.rs | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/src/poisonable/error.rs b/src/poisonable/error.rs index 1c4d60a..886b5fd 100644 --- a/src/poisonable/error.rs +++ b/src/poisonable/error.rs @@ -1,5 +1,6 @@ use core::fmt; use std::error::Error; +use std::ops::{Deref, DerefMut}; use super::{PoisonError, PoisonGuard, TryLockPoisonableError}; @@ -66,7 +67,9 @@ 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. /// @@ -96,10 +99,12 @@ impl<Guard> PoisonError<Guard> { /// println!("recovered {} items", data.len()); /// ``` #[must_use] - pub const fn get_ref(&self) -> &Guard { + pub fn get_ref(&self) -> &T { &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. /// @@ -130,7 +135,7 @@ impl<Guard> PoisonError<Guard> { /// println!("recovered {} items", data.len()); /// ``` #[must_use] - pub fn get_mut(&mut self) -> &mut Guard { + pub fn get_mut(&mut self) -> &mut T { &mut self.guard } } |
