blob: 5e9ad8a3f176a544d204f2ebd3b411910abe39f4 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
### What it does
Checks for `&mut Mutex::lock` calls
### Why is this bad?
`Mutex::lock` is less efficient than
calling `Mutex::get_mut`. In addition you also have a statically
guarantee that the mutex isn't locked, instead of just a runtime
guarantee.
### Example
```
use std::sync::{Arc, Mutex};
let mut value_rc = Arc::new(Mutex::new(42_u8));
let value_mutex = Arc::get_mut(&mut value_rc).unwrap();
let mut value = value_mutex.lock().unwrap();
*value += 1;
```
Use instead:
```
use std::sync::{Arc, Mutex};
let mut value_rc = Arc::new(Mutex::new(42_u8));
let value_mutex = Arc::get_mut(&mut value_rc).unwrap();
let value = value_mutex.get_mut().unwrap();
*value += 1;
```
|