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

Open
GuillaumeGomez wants to merge 1 commit from GuillaumeGomez/multiple-call into main
GuillaumeGomez commented 2024-06-24 14:56:33 -05:00 (Migrated from github.com)

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;
    }
}
It's quite convenient when you have multiple small conditions and want coherency across cfg handling (example with sysinfo crate): ```rust 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 2024-06-24 15:01:05 -05:00 (Migrated from github.com)

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

I'm not sure how likely new features are here considering `match_cfg` will soon be eating its lunch?
GuillaumeGomez commented 2024-06-24 15:28:07 -05:00 (Migrated from github.com)

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

`match_cfg` seems to be more limited. For example you can't have cfg conditions (handled by the macro) inside branches, unlike `cfg_if`.
This pull request has changes conflicting with the target branch.
  • src/lib.rs
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'GuillaumeGomez/multiple-call:GuillaumeGomez/multiple-call'
git switch 'GuillaumeGomez/multiple-call'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'GuillaumeGomez/multiple-call'
git switch 'GuillaumeGomez/multiple-call'
git rebase 'main'
git switch 'main'
git merge --ff-only 'GuillaumeGomez/multiple-call'
git switch 'GuillaumeGomez/multiple-call'
git rebase 'main'
git switch 'main'
git merge --no-ff 'GuillaumeGomez/multiple-call'
git switch 'main'
git merge --squash 'GuillaumeGomez/multiple-call'
git switch 'main'
git merge --ff-only 'GuillaumeGomez/multiple-call'
git switch 'main'
git merge 'GuillaumeGomez/multiple-call'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
gh-rust-lang/cfg-if!78
No description provided.