Skip to content

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

Closed
@mdinger

Description

@mdinger

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions