#cfg #syntax #attr #attr

parse_cfg

Parse Rust’s cfg(not(any(target))) attribute syntax

4 releases (stable)

2.0.0 Dec 31, 2018
1.0.1 May 20, 2018
0.1.0 May 20, 2018

#16 in #cfg

Download history 10/week @ 2021-04-04 44/week @ 2021-04-11 35/week @ 2021-04-18 2/week @ 2021-04-25 12/week @ 2021-05-02 20/week @ 2021-05-09 23/week @ 2021-05-16 2/week @ 2021-05-23 4/week @ 2021-05-30 24/week @ 2021-06-06 17/week @ 2021-06-13 9/week @ 2021-06-20 21/week @ 2021-06-27 10/week @ 2021-07-04 19/week @ 2021-07-11 44/week @ 2021-07-18

66 downloads per month
Used in cargoman

CC0 license

13KB
273 lines

cfg() expression parser

Cfg is an AST for just cfg() expressions. Target allows target triples or cfg(), so it's suitable for parsing targets Cargo allows in target.🈁️.dependencies.

Target triples used by Rust don't follow its documented syntax, so sometimes os/vendor/env will be shifted.

extern crate parse_cfg;

let cfg = "cfg(not(unix))".parse()?;
assert_eq!(Cfg::Not(Cfg::Is("unix".to_string())), cfg);

let target = "powerpc64le-unknown-linux-gnu".parse()?;
assert_eq!(Target {
    arch: "powerpc64le".to_string(),
    vendor: "unknown".to_string(),
    os: "linux".to_string(),
    env: "gnu".to_string(),
}, target);

Dependencies

~1MB
~17K SLoC