[][src]Macro switch_statement::switch

macro_rules! switch {
    ($v:expr; $($a:expr => $b:expr,)* _ => $e:expr $(,)?) => { ... };
}

Emulates a switch statement.

The syntax is similar to match except that every left-side expression is interpreted as an expression rather than a pattern. The expression to compare against must be at the beginning with a semicolon. A default case is required at the end with a _, similar to match.

Example:

use switch_statement::switch;

const A: u32 = 1 << 0;
const B: u32 = 1 << 1;

let n = 3;
let val = switch! { n;
    A => false,
    // this is a bitwise OR
    A | B => true,
    _ => false,
};
assert!(val);