Skip to content

Allow inferring enum variant types with _::Variant syntax #3167

Open
@fourbytes

Description

@fourbytes

I’ve recently been bouncing between Swift and Rust and have found the shorthand .variant syntax to be very useful. Having something similar in Rust would be very nice to have.
As initially suggested in #2830, the proposal is to allow explicitly inferring types for enum variants by using a _:: prefix.

Examples

enum CompassPoint {
    North,
    South,
    East,
    West
}

let mut direction = CompassPoint::West;
direction = _::East;
match point {
  _::East => { ... }
  _::West => { ... }
  _ => { ... }
}
fn function(cp: CompassPoint) {}

let direction = _::West;
function(direction);

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