From 8369a607ed86a31614758839b861e0017b5f86be Mon Sep 17 00:00:00 2001 From: Steve Klabnik Date: Tue, 25 Nov 2014 11:37:20 -0500 Subject: [PATCH] add slice patterns to the guide Fixes #19177. --- src/doc/guide.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/doc/guide.md b/src/doc/guide.md index 418f82c9969..92b616d9c55 100644 --- a/src/doc/guide.md +++ b/src/doc/guide.md @@ -3991,6 +3991,19 @@ match origin { } ``` +If you want to match against a slice or array, you can use `[]`: + +```{rust} +fn main() { + let v = vec!["match_this", "1"]; + + match v.as_slice() { + ["match_this", second] => println!("The second element is {}", second), + _ => {}, + } +} +``` + Whew! That's a lot of different ways to match things, and they can all be mixed and matched, depending on what you're doing: