From 5f55113a6ead937fc8bc81e361abc09b3a1565f3 Mon Sep 17 00:00:00 2001 From: Botahamec Date: Thu, 26 Sep 2024 22:39:09 -0400 Subject: Reduce the number of dereferences needed --- src/poisonable/error.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'src/poisonable/error.rs') 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 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. /// @@ -96,10 +99,12 @@ impl PoisonError { /// println!("recovered {} items", data.len()); /// ``` #[must_use] - pub const fn get_ref(&self) -> &Guard { + pub fn get_ref(&self) -> &T { &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. /// @@ -130,7 +135,7 @@ impl PoisonError { /// 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 } } -- cgit v1.2.3