macro_rules! rmatch {
([$min:literal $max:literal] $val:tt
$(
$p:pat => { $e:expr }
)*
) => { ... };
}Expand description
Ranged pattern matching macro: no bounds recalculation, extended patterns
Allows to match a Ranged value over a range it covers. The feature has
the following limitations:
- The bounds must be explicitly specified; they are checked, but not inferred
- The macro syntax supports a subset of Rust pattern matching syntax
i128::MINandi128::MAXvalues must not be in range- The unclear error reporting
fn ranged_to_bool(r: Ranged<0,1>) -> bool {
rmatch!{[0 1] r // Bounds and expression (token tree,
// complex expressions must be in parentheses)
0 => {false}
1 => {true} // Complex patterns like 1..5 | 12..14 are supported
}
}