From 129c13c21254ca104bddf020170edaca1fb7107d Mon Sep 17 00:00:00 2001 From: Mica White Date: Wed, 25 Dec 2024 22:49:42 -0500 Subject: Implement common traits --- src/poisonable/guard.rs | 53 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) (limited to 'src/poisonable/guard.rs') diff --git a/src/poisonable/guard.rs b/src/poisonable/guard.rs index 6438c2d..97d1c60 100644 --- a/src/poisonable/guard.rs +++ b/src/poisonable/guard.rs @@ -1,4 +1,5 @@ use std::fmt::{Debug, Display}; +use std::hash::Hash; use std::marker::PhantomData; use std::ops::{Deref, DerefMut}; @@ -27,6 +28,32 @@ impl Drop for PoisonRef<'_, Guard> { } } +impl PartialEq for PoisonRef<'_, Guard> { + fn eq(&self, other: &Self) -> bool { + self.guard.eq(&other.guard) + } +} + +impl PartialOrd for PoisonRef<'_, Guard> { + fn partial_cmp(&self, other: &Self) -> Option { + self.guard.partial_cmp(&other.guard) + } +} + +impl Eq for PoisonRef<'_, Guard> {} + +impl Ord for PoisonRef<'_, Guard> { + fn cmp(&self, other: &Self) -> std::cmp::Ordering { + self.guard.cmp(&other.guard) + } +} + +impl Hash for PoisonRef<'_, Guard> { + fn hash(&self, state: &mut H) { + self.guard.hash(state) + } +} + impl Debug for PoisonRef<'_, Guard> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { Debug::fmt(&**self, f) @@ -65,6 +92,32 @@ impl AsMut for PoisonRef<'_, Guard> { } } +impl PartialEq for PoisonGuard<'_, '_, Guard, Key> { + fn eq(&self, other: &Self) -> bool { + self.guard.eq(&other.guard) + } +} + +impl PartialOrd for PoisonGuard<'_, '_, Guard, Key> { + fn partial_cmp(&self, other: &Self) -> Option { + self.guard.partial_cmp(&other.guard) + } +} + +impl Eq for PoisonGuard<'_, '_, Guard, Key> {} + +impl Ord for PoisonGuard<'_, '_, Guard, Key> { + fn cmp(&self, other: &Self) -> std::cmp::Ordering { + self.guard.cmp(&other.guard) + } +} + +impl Hash for PoisonGuard<'_, '_, Guard, Key> { + fn hash(&self, state: &mut H) { + self.guard.hash(state) + } +} + impl Debug for PoisonGuard<'_, '_, Guard, Key> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { Debug::fmt(&self.guard, f) -- cgit v1.2.3