Skip to content

Pattern matching: both Some(..) and Some(_) work? #18020

@scribu

Description

@scribu

In The Rust Guide, in the Patterns section, it says:

If you're matching on an enum which has variants, you can use .. to ignore the value in the variant:

match x {
    Value(..) => println!("Got an int!"),
    Missing   => println!("No such luck."),
}

but then in the Consumers section, Some(_) is used:

match greater_than_forty_two {
    Some(_) => println!("We got some numbers!"),
    None    => println!("No numbers found :("),
}

Why are both wildcard variants — .. and _ — allowed? Some(_) seems less surprising to me.

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