std-method
Mutex::get_mut: exclusive borrowed access
When a caller already owns an exclusive mutable borrow of the mutex, no additional locking is required to obtain mutable access. Poisoning still needs handling. Expected stdout (not executed): 10 Common mistake: Assuming get_mut works through a shared Arc without exclusive ownership.
Formal Syntax & Structure
rust syntaxrust
m.get_mut() -> LockResult<&mut T>Working Example
Example Snippetrust
fn main() { use std::sync::Mutex; let mut m = Mutex::new(8); *m.get_mut().unwrap() += 2; println!("{}", m.into_inner().unwrap());}