Auto merge of #26108 - Marwes:field_pun_docs, r=steveklabnik

Adds a mention for the short form pattern syntax. Now without creating a PR to my own fork!

#25779
This commit is contained in:
bors 2015-06-13 07:00:26 +00:00
commit 7c38de89d4

View File

@ -221,12 +221,27 @@ struct Point {
let origin = Point { x: 0, y: 0 };
match origin {
Point { x: x, y: y } => println!("({},{})", x, y),
Point { x, y } => println!("({},{})", x, y),
}
```
[struct]: structs.html
We can use `:` to give a value a different name.
```rust
struct Point {
x: i32,
y: i32,
}
let origin = Point { x: 0, y: 0 };
match origin {
Point { x: x1, y: y1 } => println!("({},{})", x1, y1),
}
```
If we only care about some of the values, we dont have to give them all names:
```rust
@ -238,7 +253,7 @@ struct Point {
let origin = Point { x: 0, y: 0 };
match origin {
Point { x: x, .. } => println!("x is {}", x),
Point { x, .. } => println!("x is {}", x),
}
```
@ -255,7 +270,7 @@ struct Point {
let origin = Point { x: 0, y: 0 };
match origin {
Point { y: y, .. } => println!("y is {}", y),
Point { y, .. } => println!("y is {}", y),
}
```