Mutex lock scope


According to the API docs we have the following definition for the lock method of Mutex:

// When the guard goes out of scope, the mutex will be unlocked.
fn lock(&self) -> LockResult<MutexGuard<T>>

Doesn’t it mean that in the following code, the actual data is modified outside the scope of the LockResult?

let data = Arc::new(Mutex::new(0));
let mut d = data.lock().unwrap();  // Doesn't LockResult go out of scope here?
*d += 1;


Yeah, LockResult does go out of scope, but we care about the MutexGuard, not the LockResult


Ah, ok, I see. Thanks!