std-method

Mutex::into_inner: consume the lock

Consume an owned mutex to recover its contents. This is appropriate after ownership of the synchronization object is no longer shared. A poisoned mutex may still return an error containing the value. Expected stdout (not executed): report Common mistake: Expecting to keep using a mutex after consuming it.

Formal Syntax & Structure

rust syntaxrust
m.into_inner() -> LockResult<T>

Working Example

Example Snippetrust
fn main() {    use std::sync::Mutex;    let m = Mutex::new(String::from("report"));    let text = m.into_inner().unwrap();    println!("{text}");}
Rust Reference