summaryrefslogtreecommitdiff
path: root/src/collection
diff options
context:
space:
mode:
authorMica White <botahamec@gmail.com>2024-12-25 22:49:42 -0500
committerMica White <botahamec@gmail.com>2024-12-26 10:54:31 -0500
commit129c13c21254ca104bddf020170edaca1fb7107d (patch)
treef6904fc15a315d9962c64f30ba73bc73b1969fcf /src/collection
parent311842d28d1fbb6da945f0d98f1655f77a58abf9 (diff)
Implement common traits
Diffstat (limited to 'src/collection')
-rw-r--r--src/collection/boxed.rs1
-rw-r--r--src/collection/guard.rs27
-rw-r--r--src/collection/retry.rs8
3 files changed, 31 insertions, 5 deletions
diff --git a/src/collection/boxed.rs b/src/collection/boxed.rs
index fca1db2..2397bd3 100644
--- a/src/collection/boxed.rs
+++ b/src/collection/boxed.rs
@@ -1,4 +1,3 @@
-use std::alloc::Layout;
use std::cell::UnsafeCell;
use std::fmt::Debug;
use std::marker::PhantomData;
diff --git a/src/collection/guard.rs b/src/collection/guard.rs
index d604680..fc8df30 100644
--- a/src/collection/guard.rs
+++ b/src/collection/guard.rs
@@ -1,10 +1,37 @@
use std::fmt::{Debug, Display};
+use std::hash::Hash;
use std::ops::{Deref, DerefMut};
use crate::key::Keyable;
use super::LockGuard;
+impl<Guard: PartialEq, Key: Keyable> PartialEq for LockGuard<'_, Guard, Key> {
+ fn eq(&self, other: &Self) -> bool {
+ self.guard.eq(&other.guard)
+ }
+}
+
+impl<Guard: PartialOrd, Key: Keyable> PartialOrd for LockGuard<'_, 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 LockGuard<'_, Guard, Key> {}
+
+impl<Guard: Ord, Key: Keyable> Ord for LockGuard<'_, Guard, Key> {
+ fn cmp(&self, other: &Self) -> std::cmp::Ordering {
+ self.guard.cmp(&other.guard)
+ }
+}
+
+impl<Guard: Hash, Key: Keyable> Hash for LockGuard<'_, Guard, Key> {
+ fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
+ self.guard.hash(state)
+ }
+}
+
impl<Guard: Debug, Key: Keyable> Debug for LockGuard<'_, Guard, Key> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
Debug::fmt(&**self, f)
diff --git a/src/collection/retry.rs b/src/collection/retry.rs
index 3f5d471..687c5ec 100644
--- a/src/collection/retry.rs
+++ b/src/collection/retry.rs
@@ -1,3 +1,7 @@
+use std::cell::RefCell;
+use std::collections::HashSet;
+use std::marker::PhantomData;
+
use crate::collection::utils;
use crate::handle_unwind::handle_unwind;
use crate::lockable::{
@@ -5,10 +9,6 @@ use crate::lockable::{
};
use crate::Keyable;
-use std::cell::RefCell;
-use std::collections::HashSet;
-use std::marker::PhantomData;
-
use super::{LockGuard, RetryingLockCollection};
/// Get all raw locks in the collection