sync: Add RwLock::into_inner method (#2321)

Add RwLock::into_inner method that consumes the lock and returns
the wrapped value.

Fixes: #2320
This commit is contained in:
Daniel Müller
2020-03-18 11:52:11 -07:00
committed by GitHub
parent 602ad2e0ba
commit c3b830110a
2 changed files with 11 additions and 0 deletions
+5
View File
@@ -244,6 +244,11 @@ impl<T> RwLock<T> {
RwLockWriteGuard { lock: self, permit }
}
/// Consumes the lock, returning the underlying data.
pub fn into_inner(self) -> T {
self.c.into_inner()
}
}
impl<T> ops::Deref for RwLockReadGuard<'_, T> {
+6
View File
@@ -11,6 +11,12 @@ use tokio::sync::{Barrier, RwLock};
use tokio_test::task::spawn;
use tokio_test::{assert_pending, assert_ready};
#[test]
fn into_inner() {
let rwlock = RwLock::new(42);
assert_eq!(rwlock.into_inner(), 42);
}
// multiple reads should be Ready
#[test]
fn read_shared() {