Skip to content

Commit 658b708

Browse files
committed
Make code examples pass mdbook test.
1 parent 246f9e6 commit 658b708

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/flow_control/let_else.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ in the surrounding scope like a normal `let`, or else diverge (e.g. `break`,
99
`return`, `panic!`) when the pattern doesn't match.
1010

1111
```rust
12+
use std::str::FromStr;
13+
1214
fn get_count_item(s: &str) -> (u64, &str) {
1315
let mut it = s.split(' ');
1416
let (Some(count_str), Some(item)) = (it.next(), it.next()) else {
@@ -19,6 +21,7 @@ fn get_count_item(s: &str) -> (u64, &str) {
1921
};
2022
(count, item)
2123
}
24+
2225
assert_eq!(get_count_item("3 chairs"), (3, "chairs"));
2326
```
2427

@@ -27,6 +30,10 @@ The scope of name bindings is the main thing that makes this different from
2730
patterns with an unfortunate bit of repetition and an outer `let`:
2831

2932
```rust
33+
# use std::str::FromStr;
34+
#
35+
# fn get_count_item(s: &str) -> (u64, &str) {
36+
# let mut it = s.split(' ');
3037
let (count_str, item) = match (it.next(), it.next()) {
3138
(Some(count_str), Some(item)) => (count_str, item),
3239
_ => panic!("Can't segment count item pair: '{s}'"),
@@ -36,6 +43,10 @@ patterns with an unfortunate bit of repetition and an outer `let`:
3643
} else {
3744
panic!("Can't parse integer: '{count_str}'");
3845
};
46+
# (count, item)
47+
# }
48+
#
49+
# assert_eq!(get_count_item("3 chairs"), (3, "chairs"));
3950
```
4051

4152
### See also:

0 commit comments

Comments
 (0)