Skip to content

Commit

Permalink
Rollup merge of rust-lang#35465 - cardoe:pattern-book-update, r=steve…
Browse files Browse the repository at this point in the history
…klabnik

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.
  • Loading branch information
Jonathan Turner authored Aug 8, 2016
2 parents 732e8f2 + 18565c6 commit 39a26c5
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/doc/book/patterns.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand All @@ -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].
Expand Down

0 comments on commit 39a26c5

Please sign in to comment.