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/guard.rs | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) (limited to 'src/poisonable/guard.rs') diff --git a/src/poisonable/guard.rs b/src/poisonable/guard.rs index a8a54fe..d1913bf 100644 --- a/src/poisonable/guard.rs +++ b/src/poisonable/guard.rs @@ -68,27 +68,33 @@ impl<'flag, Guard> AsMut for PoisonRef<'flag, Guard> { impl<'flag, 'key, Guard: Debug, Key: Keyable> Debug for PoisonGuard<'flag, 'key, Guard, Key> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - Debug::fmt(&**self, f) + Debug::fmt(&self.guard, f) } } impl<'flag, 'key, Guard: Display, Key: Keyable> Display for PoisonGuard<'flag, 'key, Guard, Key> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - Display::fmt(&**self, f) + Display::fmt(&self.guard, f) } } -impl<'flag, 'key, Guard, Key: Keyable> Deref for PoisonGuard<'flag, 'key, Guard, Key> { - type Target = Guard; +impl<'flag, 'key, T, Guard: Deref, Key: Keyable> Deref + for PoisonGuard<'flag, 'key, Guard, Key> +{ + type Target = T; fn deref(&self) -> &Self::Target { - &self.guard.guard + #[allow(clippy::explicit_auto_deref)] // fixing this results in a compiler error + &*self.guard.guard } } -impl<'flag, 'key, Guard, Key: Keyable> DerefMut for PoisonGuard<'flag, 'key, Guard, Key> { +impl<'flag, 'key, T, Guard: DerefMut, Key: Keyable> DerefMut + for PoisonGuard<'flag, 'key, Guard, Key> +{ fn deref_mut(&mut self) -> &mut Self::Target { - &mut self.guard.guard + #[allow(clippy::explicit_auto_deref)] // fixing this results in a compiler error + &mut *self.guard.guard } } -- cgit v1.2.3