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

Indicate that order doesn't matter when destructuring structures #19178

Closed
mdinger opened this issue Nov 21, 2014 · 0 comments · Fixed by #19310
Closed

Indicate that order doesn't matter when destructuring structures #19178

mdinger opened this issue Nov 21, 2014 · 0 comments · Fixed by #19310

Comments

@mdinger
Copy link
Contributor

mdinger commented Nov 21, 2014

In the patterns part of the guide, all the examples do matches forward. There should be examples with a different order to show the order isn't important:

struct Point { x: int, y: int, z: int, w: int}
let origin = Point { x: 0, y: 0, z: 0, w: 0};

// All examples do this
match origin {
    Point { x, .. } => println!("x is {}", x),
}

// If you only want the last value...this doesn't work
match origin {
    Point { ..,w } => println!("w is {}", w),
}

// Indicate that the order is irrelevant
match origin {
    Point { w, y, z, x } => println!("y is {}, w is {}", y, w),
}

// Then you can do this
match origin {
    Point { w, .. } => println!("w is {}", w),
}

cc @steveklabnik

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants