Skip to main content

feature

Macro feature 

Source
macro_rules! feature {
    (if ($name:literal) $then1:block else $(if $condition:tt $then2:block else)* $else:block) => { ... };
    (if (!$name:literal) $then1:block else $(if $condition:tt $then2:block else)* $else:block) => { ... };
    (if ($left:tt && $right:tt) $then1:block else $(if $condition:tt $then2:block else)* $else:block) => { ... };
    (if ($left:tt || $right:tt) $then1:block else $(if $condition:tt $then2:block else)* $else:block) => { ... };
    (if ($inner:tt) $then1:block else $(if $condition:tt $then2:block else)* $else:block) => { ... };
    ($else:block) => { ... };
}
Expand description

Compiles expressions conditionally on features.

ยงExamples

use cfg_elif::expr::feature;

assert_eq!(
    feature!(if ("foo") {
        0
    } else if ("bar" && "baz") {
        1
    } else if ("bar" || "baz") {
        2
    } else if (("bar" || "baz") && ("foo" || "baz")) {
        3
    } else if (!"bar") {
        42
    } else {
        4
    }),
    42
);