#cfg #macro #numbers #first #parameters #gets #structured

cfg-if

A macro to ergonomically define an item depending on a large number of #[cfg] parameters. Structured like an if-else chain, the first matching branch is the item that gets emitted.

12 releases (1 stable)

1.0.0 Oct 6, 2020
0.1.10 Sep 24, 2019
0.1.9 May 15, 2019
0.1.7 Mar 4, 2019
0.1.0 Jul 8, 2015

#48 in Rust patterns

Download history 2495106/week @ 2024-01-07 2495360/week @ 2024-01-14 2544886/week @ 2024-01-21 2747480/week @ 2024-01-28 2658537/week @ 2024-02-04 2644701/week @ 2024-02-11 2766101/week @ 2024-02-18 2880478/week @ 2024-02-25 2814697/week @ 2024-03-03 2697564/week @ 2024-03-10 2735826/week @ 2024-03-17 2772700/week @ 2024-03-24 2749688/week @ 2024-03-31 2749417/week @ 2024-04-07 2787123/week @ 2024-04-14 2775987/week @ 2024-04-21

11,251,384 downloads per month
Used in 68,033 crates (1,667 directly)

MIT/Apache

9KB
118 lines

cfg-if

Documentation

A macro to ergonomically define an item depending on a large number of #[cfg] parameters. Structured like an if-else chain, the first matching branch is the item that gets emitted.

[dependencies]
cfg-if = "0.1"

Example

cfg_if::cfg_if! {
    if #[cfg(unix)] {
        fn foo() { /* unix specific functionality */ }
    } else if #[cfg(target_pointer_width = "32")] {
        fn foo() { /* non-unix, 32-bit functionality */ }
    } else {
        fn foo() { /* fallback implementation */ }
    }
}

fn main() {
    foo();
}

License

This project is licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in cfg-if by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Dependencies

~200KB