Rust

Rust

Made by DeepSource

This match statement can be collapsed into an if-else statement RS-W1007

Anti-pattern
Minor
Autofix

match statements with only one useful arm can be reduced to an if-else statement. This helps improve readability, an if-else statement nests lesser than a match.

Use the pattern of the single match arm as the pattern within an if let statement. The body of the wildcard arm resides within the else block.

Bad practice

let v = 5;
match v {
    3..10 => {
        println!("The range 3..10 contains v!");
    },
    _ => {
        println!("v is outside the range 3..10");
    },
}

Recommended

let v = 5;
if let 3..10 = v {
    println!("The range 3..10 contains v!");
} else {
    println!("v is outside the range 3..10");
}