How to use or-patterns and match binding?

fn main() {
    let c = 'a';
    match c {
        ch @ ('a'..='z' | '0'..='9' | '-') => println!("do something with {}", ch),
        _ => return,
    }
}

What doesn't work in this example, aside from the fact that you need nightly and the #![feature(or_patterns)] in the crate root?

1 Like

Thanks! I switch to nightly and it works.

For future reference: if the compiler throws an error saying that something is experimental, this almost always means that you should switch to nightly to use it. And, if some feature has to be activated, nightly compiler will usually say which one.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.