Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

GuillaumeGomez
Copy link
Member

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
Copy link
Member

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

@GuillaumeGomez
Copy link
Member Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants