summaryrefslogtreecommitdiff
path: root/src/guard.rs
diff options
context:
space:
mode:
authorBotahamec <botahamec@outlook.com>2024-03-06 22:40:20 -0500
committerBotahamec <botahamec@outlook.com>2024-03-06 22:40:20 -0500
commit8311c58b99aa86f4a971ea208e1fb3a9a825d566 (patch)
treee30016adea76308c3017e61ca7fe5ddeb5aace2c /src/guard.rs
parentd96edbd12da892a101362ae89fb3c10917361fe6 (diff)
Added some examples
Diffstat (limited to 'src/guard.rs')
-rw-r--r--src/guard.rs23
1 files changed, 20 insertions, 3 deletions
diff --git a/src/guard.rs b/src/guard.rs
index 5ac11e9..5e29966 100644
--- a/src/guard.rs
+++ b/src/guard.rs
@@ -9,7 +9,8 @@ mod sealed {
#[allow(clippy::wildcard_imports)]
use super::*;
pub trait Sealed {}
- impl<R: RawMutex, T> Sealed for Mutex<R, T> {}
+ impl<'a, T, R: RawMutex + 'a> Sealed for Mutex<T, R> {}
+ impl<'a, T, R: RawMutex + 'a> Sealed for &Mutex<T, R> {}
impl<'a, A: Lockable<'a>, B: Lockable<'a>> Sealed for (A, B) {}
}
@@ -41,8 +42,24 @@ pub trait Lockable<'a>: sealed::Sealed {
fn unlock(guard: Self::Output);
}
-impl<'a, R: RawMutex + 'a, T: 'a> Lockable<'a> for Mutex<R, T> {
- type Output = MutexRef<'a, R, T>;
+impl<'a, T: 'a, R: RawMutex + 'a> Lockable<'a> for Mutex<T, R> {
+ type Output = MutexRef<'a, T, R>;
+
+ unsafe fn lock(&'a self) -> Self::Output {
+ self.lock_ref()
+ }
+
+ unsafe fn try_lock(&'a self) -> Option<Self::Output> {
+ self.try_lock_ref()
+ }
+
+ fn unlock(guard: Self::Output) {
+ drop(guard);
+ }
+}
+
+impl<'a, T: 'a, R: RawMutex + 'a> Lockable<'a> for &Mutex<T, R> {
+ type Output = MutexRef<'a, T, R>;
unsafe fn lock(&'a self) -> Self::Output {
self.lock_ref()