]> git.lizzy.rs Git - rust.git/blob - src/docs/or_then_unwrap.txt
[Arithmetic] Consider literals
[rust.git] / src / docs / or_then_unwrap.txt
1 ### What it does
2 Checks for `.or(…).unwrap()` calls to Options and Results.
3
4 ### Why is this bad?
5 You should use `.unwrap_or(…)` instead for clarity.
6
7 ### Example
8 ```
9 // Result
10 let value = result.or::<Error>(Ok(fallback)).unwrap();
11
12 // Option
13 let value = option.or(Some(fallback)).unwrap();
14 ```
15 Use instead:
16 ```
17 // Result
18 let value = result.unwrap_or(fallback);
19
20 // Option
21 let value = option.unwrap_or(fallback);
22 ```