macro_rules! static_cond_item {
(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 item.
Currently limited to equality comparison. Can compare any two token trees. Can be nested.
This macro only works in item-position, see static_cond for a macro that works in expression-position.
ยงExamples
static_cond_item!{
if (+ 1 [2 3]) == (+ 1 [2 3]) {
static_cond_item!{if black != white {
fn foo() -> &'static str {"ok"}
} else {
the compiler will never even try to interpret this
}}
} else {
blah blah blah blah blah unreachable
}
}
assert_eq!(foo(), "ok");The actual conditional and the code provided for the branches not followed is eliminated after
macro expansion (check rustc --pretty=expanded).