1
Fork 0

std: clarify Mutex::get_mut more clearly

Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
This commit is contained in:
xizheyin 2025-03-31 14:53:39 +08:00
parent ae8ab87de4
commit 04d9d864b3
No known key found for this signature in database
GPG key ID: 0A0D90BE99CEDEAD

View file

@ -582,7 +582,9 @@ impl<T: ?Sized> Mutex<T> {
/// 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.
/// take place -- the mutable borrow statically guarantees no new locks can be acquired
/// while this reference exists. Note that this method does not clear any previous abandoned locks
/// (e.g., via [`forget()`] on a [`MutexGuard`]).
///
/// # Errors
///
@ -599,6 +601,8 @@ impl<T: ?Sized> Mutex<T> {
/// *mutex.get_mut().unwrap() = 10;
/// assert_eq!(*mutex.lock().unwrap(), 10);
/// ```
///
/// [`forget()`]: mem::forget
#[stable(feature = "mutex_get_mut", since = "1.6.0")]
pub fn get_mut(&mut self) -> LockResult<&mut T> {
let data = self.data.get_mut();