diff --git a/tokio/src/sync/rwlock/owned_read_guard.rs b/tokio/src/sync/rwlock/owned_read_guard.rs index 273e7b86f2f..f50b2abcaf5 100644 --- a/tokio/src/sync/rwlock/owned_read_guard.rs +++ b/tokio/src/sync/rwlock/owned_read_guard.rs @@ -138,6 +138,32 @@ impl OwnedRwLockReadGuard { resource_span: this.resource_span, }) } + + /// Returns a reference to the original `Arc`. + /// + /// # Examples + /// + /// ``` + /// use std::sync::Arc; + /// use tokio::sync::{RwLock, OwnedRwLockReadGuard}; + /// + /// #[derive(Debug, Clone, Copy, PartialEq, Eq)] + /// struct Foo(u32); + /// + /// # #[tokio::main] + /// # async fn main() { + /// let lock = Arc::new(RwLock::new(Foo(1))); + /// + /// let guard = lock.clone().read_owned().await; + /// assert!(Arc::ptr_eq(&lock, OwnedRwLockReadGuard::rwlock(&guard))); + /// + /// let guard = OwnedRwLockReadGuard::map(guard, |f| &f.0); + /// assert!(Arc::ptr_eq(&lock, OwnedRwLockReadGuard::rwlock(&guard))); + /// # } + /// ``` + pub fn rwlock(this: &Self) -> &Arc> { + &this.lock + } } impl ops::Deref for OwnedRwLockReadGuard { diff --git a/tokio/src/sync/rwlock/owned_write_guard.rs b/tokio/src/sync/rwlock/owned_write_guard.rs index a8ce4a1603f..11be26a9bad 100644 --- a/tokio/src/sync/rwlock/owned_write_guard.rs +++ b/tokio/src/sync/rwlock/owned_write_guard.rs @@ -390,6 +390,26 @@ impl OwnedRwLockWriteGuard { guard } + + /// Returns a reference to the original `Arc`. + /// + /// # Examples + /// + /// ``` + /// use std::sync::Arc; + /// use tokio::sync::{RwLock, OwnedRwLockWriteGuard}; + /// + /// # #[tokio::main] + /// # async fn main() { + /// let lock = Arc::new(RwLock::new(1)); + /// + /// let guard = lock.clone().write_owned().await; + /// assert!(Arc::ptr_eq(&lock, OwnedRwLockWriteGuard::rwlock(&guard))); + /// # } + /// ``` + pub fn rwlock(this: &Self) -> &Arc> { + &this.lock + } } impl ops::Deref for OwnedRwLockWriteGuard { diff --git a/tokio/src/sync/rwlock/owned_write_guard_mapped.rs b/tokio/src/sync/rwlock/owned_write_guard_mapped.rs index 9f4952100a5..e0699d09794 100644 --- a/tokio/src/sync/rwlock/owned_write_guard_mapped.rs +++ b/tokio/src/sync/rwlock/owned_write_guard_mapped.rs @@ -155,6 +155,31 @@ impl OwnedRwLockMappedWriteGuard { resource_span: this.resource_span, }) } + + /// Returns a reference to the original `Arc`. + /// + /// # Examples + /// + /// ``` + /// use std::sync::Arc; + /// use tokio::sync::{ + /// RwLock, + /// OwnedRwLockWriteGuard, + /// OwnedRwLockMappedWriteGuard, + /// }; + /// + /// # #[tokio::main] + /// # async fn main() { + /// let lock = Arc::new(RwLock::new(1)); + /// + /// let guard = lock.clone().write_owned().await; + /// let guard = OwnedRwLockWriteGuard::map(guard, |x| x); + /// assert!(Arc::ptr_eq(&lock, OwnedRwLockMappedWriteGuard::rwlock(&guard))); + /// # } + /// ``` + pub fn rwlock(this: &Self) -> &Arc> { + &this.lock + } } impl ops::Deref for OwnedRwLockMappedWriteGuard {