5 个版本
使用旧的 Rust 2015
0.2.2 | 2021 年 4 月 20 日 |
---|---|
0.2.1 | 2018 年 4 月 13 日 |
0.2.0 | 2017 年 5 月 31 日 |
0.1.1 | 2017 年 5 月 30 日 |
0.1.0 | 2017 年 5 月 29 日 |
#100 in 构建工具
208,397 个月下载量
用于 261 个 crate(2 个直接使用)
12KB
139 行
build_const
:创建构建脚本中的常量的 crate
Rust 库,用于从 build.rs 或脚本中创建可导入的常量
lib.rs
:
build_const
:创建构建脚本中的常量的 crate
build_const crate 的存在是为了帮助在编译时或在生成脚本中创建 rust 常量文件。它非常简单轻量,使得常量创建变得简单。
推荐用法:在开发过程中,在 build.rs
中创建您的常量。一旦您的常量相当稳定,请创建一个脚本,并将常量文件生成在一个单独的文件中,或是一个外部 crate,您可以将它作为依赖项引入。
示例
在您的 Cargo.toml
文件中包含 build_const = VERSION
。对于 no_std
支持(仅宏)使用 default-features = false
。
请参阅 ConstWriter
了解如何在 build.rs 或脚本中使用。要导入在 build.rs
中创建的 "constants.rs" 文件,请使用
#[macro_use]
extern crate build_const;
build_const!("constants");
println!("VALUE: {}", VALUE);
println!("VALUE: {}", ARRAY);
对于在脚本中写入常量,还提供了宏 src_file!
。
// will write files to `/src/constants.rs`
let mut consts = ConstWriter::from_path(&Path::from(src_file!("constants.rs"))).unwrap();
// ... use consts