From 18565c63db1982b927b291b9597368efc615d91c Mon Sep 17 00:00:00 2001 From: Doug Goldstein Date: Sun, 7 Aug 2016 10:14:01 -0500 Subject: [PATCH] book: update example patterns to be more clear When using Point { x: 0, y: 0 } and showing pattern matching decomposing x and y individually its hard to understand. By using a different value for x and a different value for y it is more clear. --- src/doc/book/patterns.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/doc/book/patterns.md b/src/doc/book/patterns.md index a0245d4c7b163..910b13754767f 100644 --- a/src/doc/book/patterns.md +++ b/src/doc/book/patterns.md @@ -109,14 +109,14 @@ struct Point { y: i32, } -let origin = Point { x: 0, y: 0 }; +let point = Point { x: 2, y: 3 }; -match origin { +match point { Point { x, .. } => println!("x is {}", x), } ``` -This prints `x is 0`. +This prints `x is 2`. You can do this kind of match on any member, not only the first: @@ -126,14 +126,14 @@ struct Point { y: i32, } -let origin = Point { x: 0, y: 0 }; +let point = Point { x: 2, y: 3 }; -match origin { +match point { Point { y, .. } => println!("y is {}", y), } ``` -This prints `y is 0`. +This prints `y is 3`. This ‘destructuring’ behavior works on any compound data type, like [tuples][tuples] or [enums][enums].