1 unstable release

0.1.0 Feb 3, 2022

#2569 in Parser implementations

Download history 74/week @ 2024-01-07 117/week @ 2024-01-14 116/week @ 2024-01-21 8/week @ 2024-01-28 34/week @ 2024-02-11 16/week @ 2024-02-18 16/week @ 2024-02-25 110/week @ 2024-03-10 69/week @ 2024-03-17 184/week @ 2024-03-24 41/week @ 2024-03-31 66/week @ 2024-04-07 2/week @ 2024-04-14 9/week @ 2024-04-21

120 downloads per month

MIT license

20KB
403 lines

rust_cfg_parser - Parser for rust cfg() expression

Build Status Crates.io Docs

Usage

To use rust_cfg_parser in your project, add the following to your Cargo.toml:

[dependencies]
rust_cfg_parser = "0.1.0"

Example

use rust_cfg_parser::{CfgValue, parse};

let expr = parse("cfg(windows)").unwrap();

let matches = expr.matches(&[CfgValue::Name("linux".to_string())]);
assert_eq!(false, matches);

let matches = expr.matches(&[CfgValue::Name("windows".to_string())]);
assert_eq!(true, matches);

let expr = parse("cfg(all(any(target_arch =\"x86_64\", target_arch = \"aarch64\"), target_os = \"windows\"))").unwrap();
assert_eq!(
    true,
    expr.matches(&[
        CfgValue::KeyPair("target_arch".to_string(), "x86_64".to_string()),
        CfgValue::KeyPair("target_os".to_string(), "windows".to_string())
    ])
);

License: MIT

Dependencies

~4KB