7个版本 (破坏性更新)
使用旧的Rust 2015
0.6.1 | 2017年11月15日 |
---|---|
0.6.0 | 2017年11月10日 |
0.5.0 | 2017年11月10日 |
0.4.0 | 2017年11月10日 |
0.1.0 | 2017年11月10日 |
#648 在 构建工具 中
每月25次下载
8KB
build_script_file_gen
一个Rust库,它封装了通过构建脚本生成文件并在构建时在源文件中包含其内容的便捷方法。
- 在build.rs(构建脚本)中,执行以下操作:
extern crate build_script_file_gen;
use build_script_file_gen::gen_file_str;
fn main() {
let string_content = "Hello World!";
gen_file_str("hello.txt", &string_content);
//or
let rust_code = r#"println!("Hello World!");"#;
gen_file_str("hello.rs", &rust_code);
}
- 在你的模块中,执行以下操作:
#[macro_use]
extern crate build_script_file_gen;
fn main() {
//hello.txt contains the text: Hello World!;
//which will make this function print Hello World! when compiled
println!(include_file_str!("hello.txt"));
//or
//hello.rs contains the text: println!("Hello World!");
//which will make this function print Hello World! when compiled
include_file!("hello.rs");
}
lib.rs
:
此模块封装了通过构建脚本生成文件并在构建时在源文件中包含其内容的便捷方法。
示例
//Step 1: In build.rs (build script) do,
extern crate build_script_file_gen;
use build_script_file_gen::gen_file_str;
fn main() {
let string_content = "Hello World!";
gen_file_str("hello.txt", &string_content);
//or
let rust_code = r#"println!("Hello World!");"#;
gen_file_str("hello.rs", &rust_code);
}
//Step 2: In your module do,
#[macro_use]
extern crate build_script_file_gen;
fn main() {
//hello.txt contains the text: Hello World!;
//which will make this function print Hello World! when compiled
println!(include_file_str!("hello.txt"));
//or
//hello.rs contains the text: println!("Hello World!");
//which will make this function print Hello World! when compiled
include_file!("hello.rs");
}