Skip to content

Commit 8369a60

Browse files
committed
add slice patterns to the guide
Fixes #19177.
1 parent 48ca6d1 commit 8369a60

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/doc/guide.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3991,6 +3991,19 @@ match origin {
39913991
}
39923992
```
39933993

3994+
If you want to match against a slice or array, you can use `[]`:
3995+
3996+
```{rust}
3997+
fn main() {
3998+
let v = vec!["match_this", "1"];
3999+
4000+
match v.as_slice() {
4001+
["match_this", second] => println!("The second element is {}", second),
4002+
_ => {},
4003+
}
4004+
}
4005+
```
4006+
39944007
Whew! That's a lot of different ways to match things, and they can all be
39954008
mixed and matched, depending on what you're doing:
39964009

0 commit comments

Comments
 (0)