#cfg #if #macro #chain

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.

11 releases

✓ Uses Rust 2018 edition

0.1.10 Sep 24, 2019
0.1.9 May 15, 2019
0.1.7 Mar 4, 2019
0.1.6 Oct 20, 2018
0.1.0 Jul 8, 2015
Download history 204323/week @ 2019-12-17 133662/week @ 2019-12-24 159929/week @ 2019-12-31 225716/week @ 2020-01-07 215498/week @ 2020-01-14 224876/week @ 2020-01-21 210030/week @ 2020-01-28 210554/week @ 2020-02-04 200888/week @ 2020-02-11 192316/week @ 2020-02-18 202065/week @ 2020-02-25 208077/week @ 2020-03-03 206797/week @ 2020-03-10 215533/week @ 2020-03-17 216639/week @ 2020-03-24 195836/week @ 2020-03-31

916,132 downloads per month
Used in 15,417 crates (331 directly)

MIT/Apache

8KB
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

~140KB