#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.

10 releases

0.1.9 May 15, 2019
0.1.7 Mar 4, 2019
0.1.6 Oct 20, 2018
0.1.4 Jun 27, 2018
0.1.0 Jul 8, 2015
Download history 117195/week @ 2019-04-26 119400/week @ 2019-05-03 141734/week @ 2019-05-10 148033/week @ 2019-05-17 157610/week @ 2019-05-24 152883/week @ 2019-05-31 144002/week @ 2019-06-07 143989/week @ 2019-06-14 145285/week @ 2019-06-21 137115/week @ 2019-06-28 136064/week @ 2019-07-05 139904/week @ 2019-07-12 145750/week @ 2019-07-19 147081/week @ 2019-07-26 152199/week @ 2019-08-02

560,736 downloads per month
Used in 11,323 crates (217 directly)

MIT/Apache

8KB
89 lines

cfg-if

Build Status

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

#[macro_use]
extern crate 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 Serde by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

No runtime deps