From 72beb1f88501c6324d6f337e28541f1e84e40833 Mon Sep 17 00:00:00 2001 From: Steve Klabnik Date: Tue, 25 Nov 2014 11:31:49 -0500 Subject: [PATCH] Extra note about struct matching order Fixes #19178 --- src/doc/guide.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/doc/guide.md b/src/doc/guide.md index 418f82c996957..8f2aea0de54d7 100644 --- a/src/doc/guide.md +++ b/src/doc/guide.md @@ -3991,6 +3991,22 @@ match origin { } ``` +You can do this kind of match on any member, not just the first: + +```{rust} +# #![allow(non_shorthand_field_patterns)] +struct Point { + x: int, + y: int, +} + +let origin = Point { x: 0i, y: 0i }; + +match origin { + Point { y: y, .. } => println!("y is {}", y), +} +``` + 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: