mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-08-25 00:00:18 +02:00
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:
@@ -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> {
|
||||
|
||||
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user