]> git.lizzy.rs Git - rust.git/blob - src/docs/single_match_else.txt
[Arithmetic] Consider literals
[rust.git] / src / docs / single_match_else.txt
1 ### What it does
2 Checks for matches with two arms where an `if let else` will
3 usually suffice.
4
5 ### Why is this bad?
6 Just readability – `if let` nests less than a `match`.
7
8 ### Known problems
9 Personal style preferences may differ.
10
11 ### Example
12 Using `match`:
13
14 ```
15 match x {
16     Some(ref foo) => bar(foo),
17     _ => bar(&other_ref),
18 }
19 ```
20
21 Using `if let` with `else`:
22
23 ```
24 if let Some(ref foo) = x {
25     bar(foo);
26 } else {
27     bar(&other_ref);
28 }
29 ```