diff options
| author | Mica White <botahamec@gmail.com> | 2024-12-25 22:49:42 -0500 |
|---|---|---|
| committer | Mica White <botahamec@gmail.com> | 2024-12-26 10:54:31 -0500 |
| commit | 129c13c21254ca104bddf020170edaca1fb7107d (patch) | |
| tree | f6904fc15a315d9962c64f30ba73bc73b1969fcf /src/poisonable/guard.rs | |
| parent | 311842d28d1fbb6da945f0d98f1655f77a58abf9 (diff) | |
Implement common traits
Diffstat (limited to 'src/poisonable/guard.rs')
| -rw-r--r-- | src/poisonable/guard.rs | 53 |
1 files changed, 53 insertions, 0 deletions
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<Guard> Drop for PoisonRef<'_, Guard> { } } +impl<Guard: PartialEq> PartialEq for PoisonRef<'_, Guard> { + fn eq(&self, other: &Self) -> bool { + self.guard.eq(&other.guard) + } +} + +impl<Guard: PartialOrd> PartialOrd for PoisonRef<'_, Guard> { + fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> { + self.guard.partial_cmp(&other.guard) + } +} + +impl<Guard: Eq> Eq for PoisonRef<'_, Guard> {} + +impl<Guard: Ord> Ord for PoisonRef<'_, Guard> { + fn cmp(&self, other: &Self) -> std::cmp::Ordering { + self.guard.cmp(&other.guard) + } +} + +impl<Guard: Hash> Hash for PoisonRef<'_, Guard> { + fn hash<H: std::hash::Hasher>(&self, state: &mut H) { + self.guard.hash(state) + } +} + impl<Guard: Debug> Debug for PoisonRef<'_, Guard> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { Debug::fmt(&**self, f) @@ -65,6 +92,32 @@ impl<Guard> AsMut<Guard> for PoisonRef<'_, Guard> { } } +impl<Guard: PartialEq, Key: Keyable> PartialEq for PoisonGuard<'_, '_, Guard, Key> { + fn eq(&self, other: &Self) -> bool { + self.guard.eq(&other.guard) + } +} + +impl<Guard: PartialOrd, Key: Keyable> PartialOrd for PoisonGuard<'_, '_, Guard, Key> { + fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> { + self.guard.partial_cmp(&other.guard) + } +} + +impl<Guard: Eq, Key: Keyable> Eq for PoisonGuard<'_, '_, Guard, Key> {} + +impl<Guard: Ord, Key: Keyable> Ord for PoisonGuard<'_, '_, Guard, Key> { + fn cmp(&self, other: &Self) -> std::cmp::Ordering { + self.guard.cmp(&other.guard) + } +} + +impl<Guard: Hash, Key: Keyable> Hash for PoisonGuard<'_, '_, Guard, Key> { + fn hash<H: std::hash::Hasher>(&self, state: &mut H) { + self.guard.hash(state) + } +} + impl<Guard: Debug, Key: Keyable> Debug for PoisonGuard<'_, '_, Guard, Key> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { Debug::fmt(&self.guard, f) |
