#cfg #if #macro #chain #structured #number

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.

8 releases

0.1.7 Mar 4, 2019
0.1.6 Oct 20, 2018
0.1.5 Aug 13, 2018
0.1.4 Jun 27, 2018
0.1.0 Jul 8, 2015
Download history 70247/week @ 2018-12-20 72836/week @ 2018-12-27 98397/week @ 2019-01-03 99526/week @ 2019-01-10 107561/week @ 2019-01-17 100249/week @ 2019-01-24 109491/week @ 2019-01-31 114473/week @ 2019-02-07 109706/week @ 2019-02-14 116986/week @ 2019-02-21 134022/week @ 2019-02-28 141611/week @ 2019-03-07 129551/week @ 2019-03-14 119773/week @ 2019-03-21 124020/week @ 2019-03-28

494,110 downloads per month
Used in 8,859 crates (161 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