summaryrefslogtreecommitdiff
path: root/src/guard.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/guard.rs')
-rw-r--r--src/guard.rs16
1 files changed, 8 insertions, 8 deletions
diff --git a/src/guard.rs b/src/guard.rs
index 3c1b636..30e7d4a 100644
--- a/src/guard.rs
+++ b/src/guard.rs
@@ -1,17 +1,17 @@
use std::ops::{Deref, DerefMut};
-use crate::{lockable::Lockable, ThreadKey};
+use crate::{key::Keyable, lockable::Lockable};
/// A guard for a generic [`Lockable`] type.
-pub struct LockGuard<'a, L: Lockable<'a>> {
+pub struct LockGuard<'a, L: Lockable<'a>, Key: Keyable> {
guard: L::Output,
- _key: &'a mut ThreadKey,
+ _key: Key,
}
-impl<'a, L: Lockable<'a>> LockGuard<'a, L> {
+impl<'a, L: Lockable<'a>, Key: Keyable> LockGuard<'a, L, Key> {
/// Locks the lockable type and returns a guard that can be used to access
/// the underlying data.
- pub fn lock(lock: &'a L, key: &'a mut ThreadKey) -> Self {
+ pub fn lock(lock: &'a L, key: Key) -> Self {
Self {
// safety: we have the thread's key
guard: unsafe { lock.lock() },
@@ -22,7 +22,7 @@ impl<'a, L: Lockable<'a>> LockGuard<'a, L> {
/// Attempts to lock the guard without blocking. If successful, this method
/// returns a guard that can be used to access the data. Otherwise, the key
/// is given back as an error.
- pub fn try_lock(lock: &'a L, key: &'a mut ThreadKey) -> Option<Self> {
+ pub fn try_lock(lock: &'a L, key: Key) -> Option<Self> {
// safety: we have the thread's key
unsafe { lock.try_lock() }.map(|guard| Self { guard, _key: key })
}
@@ -35,7 +35,7 @@ impl<'a, L: Lockable<'a>> LockGuard<'a, L> {
}
}
-impl<'a, L: Lockable<'a>> Deref for LockGuard<'a, L> {
+impl<'a, L: Lockable<'a>, Key: Keyable> Deref for LockGuard<'a, L, Key> {
type Target = L::Output;
fn deref(&self) -> &Self::Target {
@@ -43,7 +43,7 @@ impl<'a, L: Lockable<'a>> Deref for LockGuard<'a, L> {
}
}
-impl<'a, L: Lockable<'a>> DerefMut for LockGuard<'a, L> {
+impl<'a, L: Lockable<'a>, Key: Keyable> DerefMut for LockGuard<'a, L, Key> {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.guard
}