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

request: Multiple match patterns #783

Open
VorpalBlade opened this issue Jul 28, 2024 · 0 comments
Open

request: Multiple match patterns #783

VorpalBlade opened this issue Jul 28, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@VorpalBlade
Copy link
Contributor

In rust you can write this:

match my_var {
    "a" | "b" | "c" => do_something()
    // ...
}

This disjunction syntax doesn't work in Rune though it seems which makes code needlessly verbose:

    match os_id {
        "arch" => {
            settings.enable_pkg_backend("pacman")?;
            settings.set_file_backend("pacman")?
        }
        "manjaro" => {
            settings.enable_pkg_backend("pacman")?;
            settings.set_file_backend("pacman")?
        }
        "debian" => {
            settings.enable_pkg_backend("apt")?;
            settings.set_file_backend("apt")?
        }
        "ubuntu" => {
            settings.enable_pkg_backend("apt")?;
            settings.set_file_backend("apt")?
        }
        "mint" => {
            settings.enable_pkg_backend("apt")?;
            settings.set_file_backend("apt")?
        }
        _ => return Err("Unsupported OS")?,
    }

This would be much preferable:

    match os_id {
        "arch" | "manjaro" => {
            settings.enable_pkg_backend("pacman")?;
            settings.set_file_backend("pacman")?
        }
        "debian" | "ubuntu" | "mint" => {
            settings.enable_pkg_backend("apt")?;
            settings.set_file_backend("apt")?
        }
        _ => return Err("Unsupported OS")?,
    }
@udoprog udoprog added the enhancement New feature or request label Jul 28, 2024
@udoprog udoprog changed the title Syntax feature request: match disjunctions request: Multiple match patterns Jul 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants