pub fn map<U: ?Sized, F>(this: Self, cb: F) -> RwLockWriteGuard<'rwlock, U>
        where F: FnOnce(&'rwlock mut T) -> &'rwlock mut U
    {
        // Compute the new data while still owning the original lock
        // in order to correctly poison if the callback panics.
        let data = unsafe { ptr::read(&this.__data) };
        let new_data = cb(unsafe { &mut *data.get() });

        // We don't want to unlock the lock by running the destructor of the
        // original lock, so just read the fields we need and forget it.
        let (poison, lock) = unsafe {
            (ptr::read(&this.__poison), ptr::read(&this.__lock))
        };
        mem::forget(this);

        RwLockWriteGuard {
            __lock: lock,
            __data: unsafe { mem::transmute::<&mut U, &UnsafeCell<U>>(new_data) },
            __poison: poison,
            __marker: marker::PhantomData
        }
    }
/// Transform this guard to hold a sub-borrow of the original data.
///
/// Applies the supplied closure to the data, returning a new lock
/// guard referencing the borrow returned by the closure.
///
/// # Examples
///
/// ```rust
/// # use rwlock2::{RwLockWriteGuard, RwLock};
/// let x = RwLock::new(vec![1, 2]);
///
/// {
///     let mut y = RwLockWriteGuard::map(x.write().unwrap(), |v| &mut v[0]);
///     assert_eq!(*y, 1);
///
///     *y = 10;
/// }
///
/// assert_eq!(&**x.read().unwrap(), &[10, 2]);
/// ```
Transform this guard to hold a sub-borrow of the original data.
Applies the supplied closure to the data, returning a new lock
guard referencing the borrow returned by the closure.
Transform this guard to hold a sub - borrow of the original data . Applies the supplied closure to the data returning a new lock guard referencing the borrow returned by the closure .
pub fn map<U: ?Sized, F>(this: Self, cb: F) -> RwLockWriteGuard<'rwlock, U>
        where F: FnOnce(&'rwlock mut T) -> &'rwlock mut U
    {
        // Compute the new data while still owning the original lock
        // in order to correctly poison if the callback panics.
        let data = unsafe { ptr::read(&this.__data) };
        let new_data = cb(unsafe { &mut *data.get() });
        // We don't want to unlock the lock by running the destructor of the
        // original lock, so just read the fields we need and forget it.
        let (poison, lock) = unsafe {
            (ptr::read(&this.__poison), ptr::read(&this.__lock))
        };
        mem::forget(this);
        RwLockWriteGuard {
            __lock: lock,
            __data: unsafe { mem::transmute::<&mut U, &UnsafeCell<U>>(new_data) },
            __poison: poison,
            __marker: marker::PhantomData
        }
    }
pub fn map < U : ? Sized , F > ( this : Self , cb : F ) -> RwLockWriteGuard < ' rwlock , U > where F : FnOnce ( & ' rwlock mut T ) -> & ' rwlock mut U { // Compute the new data while still owning the original lock // in order to correctly poison if the callback panics. let data = unsafe { ptr :: read ( & this . __data ) } ; let new_data = cb ( unsafe { & mut * data . get ( ) } ) ; // We don't want to unlock the lock by running the destructor of the // original lock, so just read the fields we need and forget it. let ( poison , lock ) = unsafe { ( ptr :: read ( & this . __poison ) , ptr :: read ( & this . __lock ) ) } ; mem :: forget ( this ) ; RwLockWriteGuard { __lock : lock , __data : unsafe { mem :: transmute :: < & mut U , & UnsafeCell < U > > ( new_data ) } , __poison : poison , __marker : marker :: PhantomData } }
Transform this guard to hold a sub-borrow of the original data.
Transform this guard to hold a sub - borrow of the original data .
this
Self
cb
F
this
Self
cb
F
examples
None
use rwlock2::{rwlockwriteguard, rwlock};


{
let mut y = RwLockWriteGuard::map(x.write().unwrap(), |v| &mut v[0]);
assert_eq!(*y, 1).




{ let mut y = RwLockWriteGuard :: map ( x . write () . unwrap () |v| &mut v [ 0 ] ) ; assert_eq! ( * y 1 ) .