Crate build_script_file_gen [−] [src]
This module encapsulates convenience methods to generate files via build scripts and include their content within source files during build time.
Examples
//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"); }
Macros
include_file |
Places the content of the specified file in the surrounding code unhygienically. i.e. This can be used to inject Rust code into your module. |
include_file_str |
Includes the utf8-encoded content of the specified file as a string. |
Functions
gen_file_str |
When used inside a build script (build.rs), generates a file under the specified file name and includes the specified utf8-encoded string as its content. |