Skip to content

Commit 443fc03

Browse files
committed
Remove awkward match in if_let
1 parent 57636d6 commit 443fc03

File tree

1 file changed

+0
-19
lines changed

1 file changed

+0
-19
lines changed

src/flow_control/if_let.md

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,5 @@
11
# if let
22

3-
For some use cases, when matching enums, `match` is awkward. For example:
4-
5-
```rust
6-
// Make `optional` of type `Option<i32>`
7-
let optional = Some(7);
8-
9-
match optional {
10-
Some(i) => {
11-
println!("This is a really long string and `{:?}`", i);
12-
// ^ Needed 2 indentations just so we could destructure
13-
// `i` from the option.
14-
},
15-
_ => {},
16-
// ^ Required because `match` is exhaustive. Doesn't it seem
17-
// like wasted space?
18-
};
19-
20-
```
21-
223
`if let` is cleaner for this use case and in addition allows various
234
failure options to be specified:
245

0 commit comments

Comments
 (0)