Merge #950
950: Add .into_inner() and .get_mut() to Mutex r=Dirbaio a=hulthe Similar to the methods on std Mutex, these methods allow accessing the underlying data without locking the mutex when you have exclusive access to it. Co-authored-by: Joakim Hulthe <joakim@hulthe.net>
This commit is contained in:
commit
ec10460547
@ -111,6 +111,22 @@ where
|
|||||||
|
|
||||||
Ok(MutexGuard { mutex: self })
|
Ok(MutexGuard { mutex: self })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Consumes this mutex, returning the underlying data.
|
||||||
|
pub fn into_inner(self) -> T
|
||||||
|
where
|
||||||
|
T: Sized,
|
||||||
|
{
|
||||||
|
self.inner.into_inner()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Returns a mutable reference to the underlying data.
|
||||||
|
///
|
||||||
|
/// Since this call borrows the Mutex mutably, no actual locking needs to
|
||||||
|
/// take place -- the mutable borrow statically guarantees no locks exist.
|
||||||
|
pub fn get_mut(&mut self) -> &mut T {
|
||||||
|
self.inner.get_mut()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Async mutex guard.
|
/// Async mutex guard.
|
||||||
|
Loading…
Reference in New Issue
Block a user