Skip to content

Mention field punning in the docs for patterns #26108

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 13, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions src/doc/trpl/patterns.md
Original file line number Diff line number Diff line change
Expand Up @@ -196,12 +196,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 don’t have to give them all names:

```rust
Expand All @@ -213,7 +228,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),
}
```

Expand All @@ -230,7 +245,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),
}
```

Expand Down