]>
Commit | Line | Data |
---|---|---|
f2b60f7d FG |
1 | ### What it does |
2 | Checks for if-else that could be written using either `bool::then` or `bool::then_some`. | |
3 | ||
4 | ### Why is this bad? | |
5 | Looks a little redundant. Using `bool::then` is more concise and incurs no loss of clarity. | |
6 | For simple calculations and known values, use `bool::then_some`, which is eagerly evaluated | |
7 | in comparison to `bool::then`. | |
8 | ||
9 | ### Example | |
10 | ``` | |
11 | let a = if v.is_empty() { | |
12 | println!("true!"); | |
13 | Some(42) | |
14 | } else { | |
15 | None | |
16 | }; | |
17 | ``` | |
18 | ||
19 | Could be written: | |
20 | ||
21 | ``` | |
22 | let a = v.is_empty().then(|| { | |
23 | println!("true!"); | |
24 | 42 | |
25 | }); | |
26 | ``` |