Macro libc::macros::cfg_if

source ·
macro_rules! cfg_if {
    ($(
        if #[cfg($($meta:meta),*)] { $($it:item)* }
    ) else * else {
        $($it2:item)*
    }) => { ... };
    (
        if #[cfg($($i_met:meta),*)] { $($i_it:item)* }
        $(
            else if #[cfg($($e_met:meta),*)] { $($e_it:item)* }
        )*
    ) => { ... };
    (@__items ($($not:meta,)*) ; ) => { ... };
    (@__items ($($not:meta,)*) ; ( ($($m:meta),*) ($($it:item)*) ),
     $($rest:tt)*) => { ... };
    (@__apply $m:meta, $($it:item)*) => { ... };
}
Expand description

A macro for defining #cfg if-else statements.

This is similar to the if/elif C preprocessor macro by allowing definition of a cascade of #[cfg] cases, emitting the implementation which matches first.

This allows you to conveniently provide a long list #cfg’d blocks of code without having to rewrite each clause multiple times.