summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/rwlock/read_guard.rs1
-rw-r--r--src/rwlock/rwlock.rs24
-rw-r--r--src/rwlock/write_guard.rs1
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<T, R>) -> 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<T, R: RawRwLock> From<T> for RwLock<T, R> {
impl<T: ?Sized, R> AsMut<T> for RwLock<T, R> {
fn as_mut(&mut self) -> &mut T {
- self.get_mut()
+ self.data.get_mut()
}
}
@@ -96,32 +96,12 @@ impl<T, R> RwLock<T, R> {
/// }
/// assert_eq!(lock.into_inner(), "modified");
/// ```
+ #[must_use]
pub fn into_inner(self) -> T {
self.data.into_inner()
}
}
-impl<T: ?Sized, R> RwLock<T, R> {
- /// 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<T: ?Sized, R: RawRwLock> RwLock<T, R> {
/// 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<T, R>) -> Self {
Self(mutex, PhantomData)
}