pub struct MutexGuard<'a, T: ?Sized + 'a> { /* private fields */ }
Expand description
An RAII implementation of a “scoped lock” of a mutex. When this structure is dropped (falls out of scope), the lock will be unlocked.
The data protected by the mutex can be access through this guard via its
Deref
and DerefMut
implementations
Implementations§
Source§impl<'mutex, T: ?Sized> MutexGuard<'mutex, T>
impl<'mutex, T: ?Sized> MutexGuard<'mutex, T>
Sourcepub fn map<U: ?Sized, F>(this: Self, cb: F) -> MutexGuard<'mutex, U>
pub fn map<U: ?Sized, F>(this: Self, cb: F) -> MutexGuard<'mutex, U>
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
let x = Mutex::new(vec![1, 2]);
{
let mut y = MutexGuard::map(x.lock().unwrap(), |v| &mut v[0]);
*y = 3;
}
assert_eq!(&*x.lock().unwrap(), &[3, 2]);
Sourcepub fn filter_map<U: ?Sized, E, F>(
this: Self,
cb: F,
) -> Result<MutexGuard<'mutex, U>, (Self, E)>
pub fn filter_map<U: ?Sized, E, F>( this: Self, cb: F, ) -> Result<MutexGuard<'mutex, U>, (Self, E)>
Conditionally get a new guard to a sub-borrow depending on the original contents of the guard.
Trait Implementations§
Source§impl<'mutex, T: ?Sized> Deref for MutexGuard<'mutex, T>
impl<'mutex, T: ?Sized> Deref for MutexGuard<'mutex, T>
Source§impl<'mutex, T: ?Sized> DerefMut for MutexGuard<'mutex, T>
impl<'mutex, T: ?Sized> DerefMut for MutexGuard<'mutex, T>
Auto Trait Implementations§
impl<'a, T> Freeze for MutexGuard<'a, T>where
T: ?Sized,
impl<'a, T> !RefUnwindSafe for MutexGuard<'a, T>
impl<'a, T> !Send for MutexGuard<'a, T>
impl<'a, T> !Sync for MutexGuard<'a, T>
impl<'a, T> Unpin for MutexGuard<'a, T>where
T: ?Sized,
impl<'a, T> !UnwindSafe for MutexGuard<'a, T>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more