Skip to content

Feature request: The match Control Flow Operator #1621

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

Closed
ghost opened this issue May 7, 2021 · 1 comment
Closed

Feature request: The match Control Flow Operator #1621

ghost opened this issue May 7, 2021 · 1 comment
Labels
request Requests to resolve a particular developer problem state-duplicate This issue or pull request already exists

Comments

@ghost
Copy link

ghost commented May 7, 2021

As Rust lang provided us powerful Match control flow

enum Coin {
    Penny,
    Nickel,
    Dime,
    Quarter,
}

fn value_in_cents(coin: Coin) -> u8 {
    match coin {
        Coin::Penny => 1,
        Coin::Nickel => 5,
        Coin::Dime => 10,
        Coin::Quarter => 25,
    }
}

and

fn main() {
    let x = Some(5);
    let y = 10;

    match x {
        Some(50) => println!("Got 50"),
        Some(n) if n == y => println!("Matched, n = {}", n),
        _ => println!("Default case, x = {:?}", x),
    }

    println!("at the end: x = {:?}, y = {}", x, y);
}

Would you please support Match statement ?

switch case seems not powerful than pattern matching.

https://doc.rust-lang.org/book/ch18-03-pattern-syntax.html

@lrhn lrhn transferred this issue from dart-lang/sdk May 7, 2021
@lrhn
Copy link
Member

lrhn commented May 7, 2021

Seems like a request for an expression-level switch, so a duplicate of #703 (and a number of other similar requests).

@lrhn lrhn closed this as completed May 7, 2021
@lrhn lrhn added request Requests to resolve a particular developer problem state-duplicate This issue or pull request already exists labels May 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
request Requests to resolve a particular developer problem state-duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

1 participant