#run-time #cfg #syn

no-std runtime_cfg

运行时配置标志的评估

1 个不稳定版本

0.1.0 2019年5月29日

#2262 in 开发工具

MIT/Apache

22KB
550 代码行

runtime_cfg travis crate docs

运行时评估配置标志。

用法

要在项目中使用 runtime_cfg,请将以下内容添加到您的 Cargo.toml 文件中:

[dependencies]
runtime-cfg = "0.1"

示例

use std::convert::TryFrom;

use quote::quote;

use runtime_cfg::*;

let cfg = quote! { #[cfg(all(unix, target_pointer_width = "32"))] };

let cfg = Cfg::try_from(cfg).unwrap();
assert_eq!(cfg, all(vec![name("unix"), name_value("target_pointer_width", "32")]).into());

let flags = vec![("unix", None), ("target_pointer_width", Some("32"))];
assert!(cfg.matches(&flags));


lib.rs:

运行时评估配置标志。

示例

use std::convert::TryFrom;

use quote::quote;

use runtime_cfg::*;

let cfg = quote! { #[cfg(all(unix, target_pointer_width = "32"))] };

let cfg = Cfg::try_from(cfg).unwrap();
assert_eq!(cfg, all(vec![name("unix"), name_value("target_pointer_width", "32")]).into());

let flags = vec![("unix", None), ("target_pointer_width", Some("32"))];
assert!(cfg.matches(&flags));

依赖项

~7–455KB
~11K SLoC