macro_rules! static_cond {
(@expr $lhs:tt $rhs:tt $arm1:tt $arm2:tt) => { ... };
(@item $lhs:tt $rhs:tt $arm1:tt $arm2:tt) => { ... };
(if $lhs:tt == $rhs:tt $then:tt) => { ... };
(if $lhs:tt != $rhs:tt $then:tt) => { ... };
(if $lhs:tt == $rhs:tt $then:tt else $els:tt) => { ... };
(if $lhs:tt != $rhs:tt $then:tt else $els:tt) => { ... };
}Expand description
Evaluates a conditional during macro expansion as expression.
Currently limited to equality comparison. Can compare any two token trees. Can be nested.
This macro only works in expression-position, see static_cond_item for a macro that works in item-position.
ยงExamples
let x = static_cond!(if (+ 1 [2 3]) == (+ 1 [2 3]) {
static_cond!(if black != white {
"ok"
} else {
the compiler will never even try to interpret this
})
} else {
blah blah blah blah blah unreachable
});
assert_eq!(x, "ok");The actual conditional and the code provided for the branches not followed is eliminated after
macro expansion (check rustc --pretty=expanded).