From 8311c58b99aa86f4a971ea208e1fb3a9a825d566 Mon Sep 17 00:00:00 2001 From: Botahamec Date: Wed, 6 Mar 2024 22:40:20 -0500 Subject: Added some examples --- src/guard.rs | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) (limited to 'src/guard.rs') 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 Sealed for Mutex {} + impl<'a, T, R: RawMutex + 'a> Sealed for Mutex {} + impl<'a, T, R: RawMutex + 'a> Sealed for &Mutex {} 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 { - type Output = MutexRef<'a, R, T>; +impl<'a, T: 'a, R: RawMutex + 'a> Lockable<'a> for Mutex { + type Output = MutexRef<'a, T, R>; + + unsafe fn lock(&'a self) -> Self::Output { + self.lock_ref() + } + + unsafe fn try_lock(&'a self) -> Option { + self.try_lock_ref() + } + + fn unlock(guard: Self::Output) { + drop(guard); + } +} + +impl<'a, T: 'a, R: RawMutex + 'a> Lockable<'a> for &Mutex { + type Output = MutexRef<'a, T, R>; unsafe fn lock(&'a self) -> Self::Output { self.lock_ref() -- cgit v1.2.3