rust-lang / cfg-if

A if/elif-like macro for Rust #[cfg] statements
Apache License 2.0
557 stars 40 forks source link

Allow to have multiple conditions in the same macro call #78

Open GuillaumeGomez opened 4 months ago

GuillaumeGomez commented 4 months ago

It's quite convenient when you have multiple small conditions and want coherency across cfg handling (example with sysinfo crate):

cfg_if::cfg_if! {
    if #[cfg(feature = "system")] {
        if #[cfg(not(feature = "apple-sandbox"))] {
            pub(crate) mod cpu;
            pub mod system;
            pub mod process;
        } else {
            pub use crate::sys::app_store::process;
        }
    }

    if #[cfg(feature = "disk")] {
        pub mod disk;
    }

    if #[cfg(feature = "apple-sandbox")] {
        pub use crate::sys::app_store::component;
    } else {
        pub mod component;
    }
}
ChrisDenton commented 4 months ago

I'm not sure how likely new features are here considering match_cfg will soon be eating its lunch?

GuillaumeGomez commented 4 months ago

match_cfg seems to be more limited. For example you can't have cfg conditions (handled by the macro) inside branches, unlike cfg_if.