Expand description

A very simple Rust library to parse rust cfg() expression.

Examples

use rust_cfg_parser::{parse, CfgValue};

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 = \"hermit\"))",
)
.unwrap();
assert_eq!(
    true,
    expr.matches(&[
        CfgValue::KeyPair("target_arch".to_string(), "x86_64".to_string()),
        CfgValue::KeyPair("target_os".to_string(), "hermit".to_string())
    ])
);

Structs

A struct to represent the parsed cfg string.

Defines the parser error type.

Enums

An enum type to represent the parsed cfg string.

An enum type for errors when parsing the cfg string.

An enum type to represent the parsed values in a cfg string.

Functions

Parses a string rust cfg attribute syntax to an expression that can be evaluated.