1个稳定版本
1.0.0 | 2024年6月3日 |
---|
#745 in 开发工具
69KB
832 行
nscfg
Nifty Simple CFG提供了一种改进的语法和宏,可以轻松管理一个包中所有的#[cfg]参数。查看功能获取完整的特性列表,如别名、属性、自动依赖标签文档等。
示例
将其转换成
#[cfg(any(doc, any(target_os = "linux", target_os = "macos", target_os = "windows")))]
#[cfg_attr(docsrs, doc(cfg(any(target_os = "linux", target_os = "windows", target_os = "macos"))))]
pub mod desktop_mod;
#[cfg(any(doc, any(target_os = "linux", target_os = "macos", target_os = "windows")))]
#[cfg_attr(docsrs, doc(cfg(any(target_os = "linux", target_os = "windows", target_os = "macos"))))]
pub use desktop_mod::Struct as Struct;
#[cfg(any(doc, any(target_os = "ios", target_os = "android")))]
#[cfg_attr(docsrs, doc(cfg(any(target_os = "ios", target_os = "android"))))]
pub mod mobile_mod;
#[cfg(any(doc, any(target_os = "ios", target_os = "android")))]
#[cfg_attr(docsrs, doc(cfg(any(target_os = "ios", target_os = "android"))))]
pub use mobile_mod::Struct1 as Struct1;
#[cfg(any(doc, any(target_os = "ios", target_os = "android")))]
#[cfg_attr(docsrs, doc(cfg(any(target_os = "ios", target_os = "android"))))]
pub use mobile_mod::Struct2 as Struct2;
#[cfg(any(doc, any(target_os = "ios", target_os = "android")))]
#[cfg_attr(docsrs, doc(cfg(any(target_os = "ios", target_os = "android"))))]
pub fn mobile_only_fn() {}
这样的
target_cfg!{
desktop => {
pub mod desktop_mod;
pub use desktop_mod::Struct as Struct;
},
mobile => {
pub mod mobile_mod;
pub use mobile_mod::Struct1 as Struct1;
pub use mobile_mod::Struct2 as Struct2;
pub fn mobile_only_fn() {}
}
}
查看示例获取更多用法。
安装
在您的Rust项目文件夹中执行此命令。
cargo add nscfg
依赖
nscfg没有依赖项,仅使用稳定的Rust库。
有问题?
查看nscfg维基,它包含了大量信息。