3 ms·
Does this end up replacing a large portion of if/else or switch statements?
by jgwil2 7y ago
Does this end up replacing a large portion of if/else or switch statements?
- heavenlyblue 7y agoThis is basically a switch statement :)
- jgwil2 7y agoIf it evaluates top to bottom in an order-dependent fashion then I suppose so. If it is order independent then it's more like what I want from a state machine.
- monocasa 7y agoWhat exactly are you looking for wrt to "order independent". Like, this will compile down to a computed jump table if that's what you're getting at.
- jgwil2 7y agoInsert new cases or change order without affecting behavior and statically check that all cases are covered. Unlike a switch statement or if else block where each condition is checked in order so adding more cases gets difficult.
- monocasa 7y agoAll Rust match statements as statically checked that all cases are covered by the compiler; you can't really turn that of even with unsafe blocks. How are you expecting that inserting or adding statements would change behavior?