Switch Statement For Rust
A simple macro to emulate a switch
statement in Rust.
Description
The switch!
macro looks similar to match
. But instead of pattern matching,
each left-hand-side expression is interpreted as an expression instead of a
pattern. One use case for this is to match against constants joined with
bitwise OR. The output of the macro is a match
with if
guards.
Example
const A: u32 = 1 << 0;
const B: u32 = 1 << 1;
const C: u32 = 1 << 2;
The above code expands to:
const A: u32 = 1 << 0;
const B: u32 = 1 << 1;
const C: u32 = 1 << 2;