summaryrefslogtreecommitdiff
path: root/src/rwlock/write_guard.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/rwlock/write_guard.rs')
-rw-r--r--src/rwlock/write_guard.rs37
1 files changed, 37 insertions, 0 deletions
diff --git a/src/rwlock/write_guard.rs b/src/rwlock/write_guard.rs
index 6549822..5b41c99 100644
--- a/src/rwlock/write_guard.rs
+++ b/src/rwlock/write_guard.rs
@@ -27,6 +27,18 @@ impl<'a, T: ?Sized + 'a, R: RawRwLock> DerefMut for RwLockWriteRef<'a, T, R> {
}
}
+impl<'a, T: ?Sized + 'a, R: RawRwLock> AsRef<T> for RwLockWriteRef<'a, T, R> {
+ fn as_ref(&self) -> &T {
+ self
+ }
+}
+
+impl<'a, T: ?Sized + 'a, R: RawRwLock> AsMut<T> for RwLockWriteRef<'a, T, R> {
+ fn as_mut(&mut self) -> &mut T {
+ self
+ }
+}
+
impl<'a, T: ?Sized + 'a, R: RawRwLock> Drop for RwLockWriteRef<'a, T, R> {
fn drop(&mut self) {
// safety: this guard is being destroyed, so the data cannot be
@@ -35,6 +47,15 @@ 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)
+ }
+}
+
impl<'a, 'key: 'a, T: ?Sized + 'a, Key: Keyable, R: RawRwLock> Deref
for RwLockWriteGuard<'a, 'key, T, Key, R>
{
@@ -53,6 +74,22 @@ impl<'a, 'key: 'a, T: ?Sized + 'a, Key: Keyable, R: RawRwLock> DerefMut
}
}
+impl<'a, 'key: 'a, T: ?Sized + 'a, Key: Keyable, R: RawRwLock> AsRef<T>
+ for RwLockWriteGuard<'a, 'key, T, Key, R>
+{
+ fn as_ref(&self) -> &T {
+ self
+ }
+}
+
+impl<'a, 'key: 'a, T: ?Sized + 'a, Key: Keyable, R: RawRwLock> AsMut<T>
+ for RwLockWriteGuard<'a, 'key, T, Key, R>
+{
+ fn as_mut(&mut self) -> &mut T {
+ self
+ }
+}
+
impl<'a, 'key: 'a, T: ?Sized + 'a, Key: Keyable, R: RawRwLock>
RwLockWriteGuard<'a, 'key, T, Key, R>
{