From fe2664a4e11df3f7938d5e6fc244a565906bcb46 Mon Sep 17 00:00:00 2001 From: Alice Ryhl Date: Fri, 25 Dec 2020 21:36:48 +0100 Subject: [PATCH] sync: remove RwLockWriteGuard::map and RwLockWriteGuard::try_map (#3345) --- tokio/src/sync/rwlock.rs | 108 --------------------------------------- 1 file changed, 108 deletions(-) diff --git a/tokio/src/sync/rwlock.rs b/tokio/src/sync/rwlock.rs index 750765fb4..2e72cf75d 100644 --- a/tokio/src/sync/rwlock.rs +++ b/tokio/src/sync/rwlock.rs @@ -237,114 +237,6 @@ pub struct RwLockWriteGuard<'a, T: ?Sized> { } impl<'a, T: ?Sized> RwLockWriteGuard<'a, T> { - /// Make a new `RwLockWriteGuard` for a component of the locked data. - /// - /// This operation cannot fail as the `RwLockWriteGuard` passed in already - /// locked the data. - /// - /// This is an associated function that needs to be used as - /// `RwLockWriteGuard::map(..)`. A method would interfere with methods of - /// the same name on the contents of the locked data. - /// - /// This is an asynchronous version of [`RwLockWriteGuard::map`] from the - /// [`parking_lot` crate]. - /// - /// [`RwLockWriteGuard::map`]: https://docs.rs/lock_api/latest/lock_api/struct.RwLockWriteGuard.html#method.map - /// [`parking_lot` crate]: https://crates.io/crates/parking_lot - /// - /// # Examples - /// - /// ``` - /// use tokio::sync::{RwLock, RwLockWriteGuard}; - /// - /// #[derive(Debug, Clone, Copy, PartialEq, Eq)] - /// struct Foo(u32); - /// - /// # #[tokio::main] - /// # async fn main() { - /// let lock = RwLock::new(Foo(1)); - /// - /// { - /// let mut mapped = RwLockWriteGuard::map(lock.write().await, |f| &mut f.0); - /// *mapped = 2; - /// } - /// - /// assert_eq!(Foo(2), *lock.read().await); - /// # } - /// ``` - #[inline] - pub fn map(mut this: Self, f: F) -> RwLockWriteGuard<'a, U> - where - F: FnOnce(&mut T) -> &mut U, - { - let data = f(&mut *this) as *mut U; - let s = this.s; - // NB: Forget to avoid drop impl from being called. - mem::forget(this); - RwLockWriteGuard { - s, - data, - marker: marker::PhantomData, - } - } - - /// Attempts to make a new [`RwLockWriteGuard`] for a component of - /// the locked data. The original guard is returned if the closure returns - /// `None`. - /// - /// This operation cannot fail as the `RwLockWriteGuard` passed in already - /// locked the data. - /// - /// This is an associated function that needs to be - /// used as `RwLockWriteGuard::try_map(...)`. A method would interfere with - /// methods of the same name on the contents of the locked data. - /// - /// This is an asynchronous version of [`RwLockWriteGuard::try_map`] from - /// the [`parking_lot` crate]. - /// - /// [`RwLockWriteGuard::try_map`]: https://docs.rs/lock_api/latest/lock_api/struct.RwLockWriteGuard.html#method.try_map - /// [`parking_lot` crate]: https://crates.io/crates/parking_lot - /// - /// # Examples - /// - /// ``` - /// use tokio::sync::{RwLock, RwLockWriteGuard}; - /// - /// #[derive(Debug, Clone, Copy, PartialEq, Eq)] - /// struct Foo(u32); - /// - /// # #[tokio::main] - /// # async fn main() { - /// let lock = RwLock::new(Foo(1)); - /// - /// { - /// let guard = lock.write().await; - /// let mut guard = RwLockWriteGuard::try_map(guard, |f| Some(&mut f.0)).expect("should not fail"); - /// *guard = 2; - /// } - /// - /// assert_eq!(Foo(2), *lock.read().await); - /// # } - /// ``` - #[inline] - pub fn try_map(mut this: Self, f: F) -> Result, Self> - where - F: FnOnce(&mut T) -> Option<&mut U>, - { - let data = match f(&mut *this) { - Some(data) => data as *mut U, - None => return Err(this), - }; - let s = this.s; - // NB: Forget to avoid drop impl from being called. - mem::forget(this); - Ok(RwLockWriteGuard { - s, - data, - marker: marker::PhantomData, - }) - } - /// Atomically downgrades a write lock into a read lock without allowing /// any writers to take exclusive access of the lock in the meantime. ///