]> git.lizzy.rs Git - rust.git/blob - src/docs/map_unwrap_or.txt
Merge remote-tracking branch 'upstream/master' into rustup
[rust.git] / src / docs / map_unwrap_or.txt
1 ### What it does
2 Checks for usage of `option.map(_).unwrap_or(_)` or `option.map(_).unwrap_or_else(_)` or
3 `result.map(_).unwrap_or_else(_)`.
4
5 ### Why is this bad?
6 Readability, these can be written more concisely (resp.) as
7 `option.map_or(_, _)`, `option.map_or_else(_, _)` and `result.map_or_else(_, _)`.
8
9 ### Known problems
10 The order of the arguments is not in execution order
11
12 ### Examples
13 ```
14 option.map(|a| a + 1).unwrap_or(0);
15 result.map(|a| a + 1).unwrap_or_else(some_function);
16 ```
17
18 Use instead:
19 ```
20 option.map_or(0, |a| a + 1);
21 result.map_or_else(some_function, |a| a + 1);
22 ```