mac

Macro if_cfg

source
macro_rules! if_cfg {
    ($cfg:meta $t:block else $f:block) => { ... };
    ($cfg:meta $t:block) => { ... };
}
Expand description

Compile-time conditional expression.

ยงExample

if_cfg!(test {
    println!("Crate built as a test suite");
})

Unlike if cfg!(...), this will not even compile the unused branch.

let x = if_cfg!(any(bleh, blah="bluh") {
    some_undefined_function_name();
    2 + "doesn't even typecheck"
} else {
    3
});

assert_eq!(x, 3);