From fa39064fe2f3399d27762a23c54d4703d00bd199 Mon Sep 17 00:00:00 2001 From: Botahamec Date: Wed, 22 May 2024 21:02:37 -0400 Subject: must use --- src/rwlock/read_guard.rs | 1 + src/rwlock/rwlock.rs | 24 ++---------------------- src/rwlock/write_guard.rs | 1 + 3 files changed, 4 insertions(+), 22 deletions(-) diff --git a/src/rwlock/read_guard.rs b/src/rwlock/read_guard.rs index e46078c..1eb8bfc 100644 --- a/src/rwlock/read_guard.rs +++ b/src/rwlock/read_guard.rs @@ -48,6 +48,7 @@ impl<'a, T: ?Sized + 'a, R: RawRwLock> Drop for RwLockReadRef<'a, T, R> { impl<'a, T: ?Sized + 'a, R: RawRwLock> RwLockReadRef<'a, T, R> { /// Creates an immutable reference for the underlying data of an [`RwLock`] /// without locking it or taking ownership of the key. + #[must_use] pub(crate) unsafe fn new(mutex: &'a RwLock) -> Self { Self(mutex, PhantomData) } diff --git a/src/rwlock/rwlock.rs b/src/rwlock/rwlock.rs index 9a7590a..00ce7d0 100644 --- a/src/rwlock/rwlock.rs +++ b/src/rwlock/rwlock.rs @@ -76,7 +76,7 @@ impl From for RwLock { impl AsMut for RwLock { fn as_mut(&mut self) -> &mut T { - self.get_mut() + self.data.get_mut() } } @@ -96,32 +96,12 @@ impl RwLock { /// } /// assert_eq!(lock.into_inner(), "modified"); /// ``` + #[must_use] pub fn into_inner(self) -> T { self.data.into_inner() } } -impl RwLock { - /// Returns a mutable reference to the underlying data. - /// - /// Since this call borrows the `RwLock` mutably, no actual locking needs - /// to take place. The mutable borrow statically guarantees no locks exist. - /// - /// # Examples - /// - /// ``` - /// use happylock::{RwLock, ThreadKey}; - /// - /// let key = ThreadKey::get().unwrap(); - /// let mut lock = RwLock::new(0); - /// *lock.get_mut() = 10; - /// assert_eq!(*lock.read(key), 10); - /// ``` - pub fn get_mut(&mut self) -> &mut T { - self.data.get_mut() - } -} - impl RwLock { /// Locks this `RwLock` with shared read access, blocking the current /// thread until it can be acquired. diff --git a/src/rwlock/write_guard.rs b/src/rwlock/write_guard.rs index ec622d7..5b41c99 100644 --- a/src/rwlock/write_guard.rs +++ b/src/rwlock/write_guard.rs @@ -50,6 +50,7 @@ impl<'a, T: ?Sized + 'a, R: RawRwLock> Drop for RwLockWriteRef<'a, T, R> { impl<'a, T: ?Sized + 'a, R: RawRwLock> RwLockWriteRef<'a, T, R> { /// Creates a reference to the underlying data of an [`RwLock`] without /// locking or taking ownership of the key. + #[must_use] pub(crate) unsafe fn new(mutex: &'a RwLock) -> Self { Self(mutex, PhantomData) } -- cgit v1.2.3