2020-03-05 14:36:19 +01:00
|
|
|
#![warn(clippy::if_let_mutex)]
|
|
|
|
|
2020-04-15 23:08:26 +02:00
|
|
|
use std::ops::Deref;
|
2020-03-05 14:36:19 +01:00
|
|
|
use std::sync::Mutex;
|
|
|
|
|
2020-03-18 02:51:43 +01:00
|
|
|
fn do_stuff<T>(_: T) {}
|
2020-03-05 14:36:19 +01:00
|
|
|
|
2020-03-18 23:13:06 +01:00
|
|
|
fn if_let() {
|
2020-04-15 23:08:26 +02:00
|
|
|
let m = Mutex::new(1_u8);
|
2020-03-18 02:51:43 +01:00
|
|
|
if let Err(locked) = m.lock() {
|
|
|
|
do_stuff(locked);
|
2020-03-05 14:36:19 +01:00
|
|
|
} else {
|
2020-03-18 02:51:43 +01:00
|
|
|
let lock = m.lock().unwrap();
|
|
|
|
do_stuff(lock);
|
2020-03-05 14:36:19 +01:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-04-15 23:08:26 +02:00
|
|
|
fn if_let_option() {
|
|
|
|
let m = Mutex::new(Some(0_u8));
|
|
|
|
if let Some(locked) = m.lock().unwrap().deref() {
|
|
|
|
do_stuff(locked);
|
|
|
|
} else {
|
|
|
|
let lock = m.lock().unwrap();
|
|
|
|
do_stuff(lock);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-03-05 14:36:19 +01:00
|
|
|
fn main() {}
|