diff options
| author | Mica White <botahamec@outlook.com> | 2025-03-09 20:49:56 -0400 |
|---|---|---|
| committer | Mica White <botahamec@outlook.com> | 2025-03-09 20:49:56 -0400 |
| commit | 58abf5872023aca7ee6459fa3b2e067d57923ba5 (patch) | |
| tree | 196cadda0dd4386668477ef286f9c9b09480e713 /src/mutex.rs | |
| parent | 4ba03be97e6cc7e790bbc9bfc18caaa228c8a262 (diff) | |
Finish testing and fixing
Diffstat (limited to 'src/mutex.rs')
| -rw-r--r-- | src/mutex.rs | 25 |
1 files changed, 21 insertions, 4 deletions
diff --git a/src/mutex.rs b/src/mutex.rs index 2022501..413bd8a 100644 --- a/src/mutex.rs +++ b/src/mutex.rs @@ -136,10 +136,7 @@ pub struct Mutex<T: ?Sized, R> { /// A reference to a mutex that unlocks it when dropped. /// /// This is similar to [`MutexGuard`], except it does not hold a [`Keyable`]. -pub struct MutexRef<'a, T: ?Sized + 'a, R: RawMutex>( - &'a Mutex<T, R>, - PhantomData<(&'a mut T, R::GuardMarker)>, -); +pub struct MutexRef<'a, T: ?Sized + 'a, R: RawMutex>(&'a Mutex<T, R>, PhantomData<R::GuardMarker>); /// An RAII implementation of a “scoped lock” of a mutex. /// @@ -183,6 +180,26 @@ mod tests { } #[test] + fn from_works() { + let key = ThreadKey::get().unwrap(); + let mutex: crate::Mutex<_> = Mutex::from("Hello, world!"); + + let guard = mutex.lock(key); + assert_eq!(*guard, "Hello, world!"); + } + + #[test] + fn as_mut_works() { + let key = ThreadKey::get().unwrap(); + let mut mutex = crate::Mutex::from(42); + + let mut_ref = mutex.as_mut(); + *mut_ref = 24; + + mutex.scoped_lock(key, |guard| assert_eq!(*guard, 24)) + } + + #[test] fn display_works_for_guard() { let key = ThreadKey::get().unwrap(); let mutex: crate::Mutex<_> = Mutex::new("Hello, world!"); |
