How to use expression as condition in match?

Solution for How to use expression as condition in match?
is Given Below:

How do I use an expression in a match arm? I want to handle the case of 100 being equal to 75 + 25.

fn main() {
    match 100 {
        75 + 25 => println!("100"),
//         ^ expected one of `...`, `..=`, `..`, `=>`, `if`, or `|`
        _ => unreachable!()
    };
}

Currently, you can not do this without using unstable features on the nightly compiler.

What you can write is:

fn main() {
    const A: i32 = 75 + 25;
    match 100 {
        A => println!("100"),
        _ => unreachable!()
    };
}

or as @Ry comments you can use a guard:

fn main() {
    match 100 {
        x if x == 75 + 25 => println!("100"),
        _ => unreachable!()
    };
}

However, if I was putting a complicated expression in the guard and it was in a performance-critical region, I’d be careful to check that the compiler was properly extracting it as a constant. (Should be OK if you limit yourself to const-functions…)

A new feature to support something like what you want is called inline-const and is being tracked here, and you can find some details here. If you’re willing to use unstable features on the nightly compiler then you can do this now:

#![feature(inline_const)]
fn main() {
    match 100 {
        const {75 + 25} => println!("100"),
        _ => unreachable!()
    };
}

When/if it becomes stable you can remove the feature line, which enables the unstable feature.