Skip to content
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

Add tuple .. operator example #1368

Merged
merged 1 commit into from
Aug 8, 2020
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
15 changes: 8 additions & 7 deletions src/flow_control/match/destructuring/destructure_tuple.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@ Tuples can be destructured in a `match` as follows:

```rust,editable
fn main() {
let pair = (0, -2);
// TODO ^ Try different values for `pair`
let triple = (0, -2, 3);
// TODO ^ Try different values for `triple`

println!("Tell me about {:?}", pair);
println!("Tell me about {:?}", triple);
// Match can be used to destructure a tuple
match pair {
// Destructure the second
(0, y) => println!("First is `0` and `y` is `{:?}`", y),
(x, 0) => println!("`x` is `{:?}` and last is `0`", x),
match triple {
// Destructure the second and third elements
(0, y, z) => println!("First is `0`, `y` is {:?}, and `z` is {:?}", y, z),
(1, ..) => println!("First is `1` and the rest doesn't matter"),
// `..` can be the used ignore the rest of the tuple
_ => println!("It doesn't matter what they are"),
// `_` means don't bind the value to a variable
}
Expand Down