Git Product home page Git Product logo

cfg-match's Introduction

cfg-match

Provides cfg_match and cfg_match_with_default macros

Based on: cfg-if

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

Example

#[macro_use]
extern crate cfg_match;

fn works() -> bool {
    cfg_match! {
         #[cfg(foo)] => { false },
         #[cfg(test)] => { true }
    }
}

fn works_with_default() -> bool {
    cfg_match_with_default! {
        #[cfg(foo)] => { false },
        #[cfg(bar)] => { false },
        _ => { true }
    }
}

#[test]
fn smoke() {
    assert!(works());
    assert!(works_with_default());
}

When using cfg_match and no match is possible you get a compilation error:

fn does_not_compile() -> bool {
    cfg_match! {
        #[cfg(foo)] => { false },
        #[cfg(bar)] => { false }
    }
}

You get the following error:

error: cfg_match: #[cfg(<check desired feature case>)] was not implemented.
  --> tests/xcrate.rs:45:5
   |
45 | /     cfg_match! {
46 | |         #[cfg(foo)] => { false },
...  |
51 | |         }
52 | |     }
   | |_____^
   |
   = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)

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.

cfg-match's People

Contributors

alexcrichton avatar dhylands avatar clarfonthey avatar liv-dumea avatar mgeisler avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.