#macro #cfg #build #match #numbers #statement #define

match_cfg

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

1 unstable release

Uses old Rust 2015

0.1.0 Apr 2, 2019

#684 in Rust patterns

Download history 407479/week @ 2024-07-31 435827/week @ 2024-08-07 422128/week @ 2024-08-14 429953/week @ 2024-08-21 417455/week @ 2024-08-28 470978/week @ 2024-09-04 461876/week @ 2024-09-11 613256/week @ 2024-09-18 641912/week @ 2024-09-25 992776/week @ 2024-10-02 1036917/week @ 2024-10-09 1031295/week @ 2024-10-16 579513/week @ 2024-10-23 500465/week @ 2024-10-30 509994/week @ 2024-11-06 536905/week @ 2024-11-13

2,255,430 downloads per month
Used in 1,336 crates (via solar-interface)

MIT/Apache

8KB
129 lines

match_cfg

Build Status

Documentation

Minimum Supported Rust Version: 1.13.0.

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

[dependencies]
match_cfg = "0.1"

The use_core feature is enabled by default and builds the crate with libcore as a dependency by using the #![no_std] attribute. When this feature is disabled, this crate is built without libcore support by using the #![no_core] attribute - this makes use of the #![feature(no_core)] and requires a nightly version of Rust.

Example

#[macro_use(match_cfg)]
extern crate match_cfg;

match_cfg! {
    #[cfg(unix)] => {
         fn foo() { /* unix specific functionality */ }
     }
     #[cfg(target_pointer_width = "32")] => {
         fn foo() { /* non-unix, 32-bit functionality */ }
     }
     _ => {
         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

Features