The documentation isn't clear on this...are the cases in a match statement guaranteed to be executed in order? In the case of don't-care matches, is it OK to have overlapping matches?
let a: bool;
let b: bool;
let c: bool;
let d: bool;
match (a, b, c, d) {
(true, _, _, _) => { /* ... */ }
(_, true, _, _) => { /* ... */ }
}
Essentially, can Rust's match be used as a weird sort of case filter?
Yes the match statements are guaranteed to be executed in order. These two matches are equivalent:
match (a, b) {
(true, _) => println!("first is true !"),
(_, true) => println!("second is true !"),
(_, _) => println!("none is true !"),
}
match (a, b) {
(true, _) => println!("first is true !"),
(false, true) => println!("second is true !"),
(false, false) => println!("none is true !"),
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With