crate.io package… https://crates.io/crates/embed_dir
You have the great macro include_bytes! in Rust
But sometimes is not enough. You could need to embed several files, generally in a folder.
In order to automate it, this simple and small tool generates code for you.
|
Note
|
Perhaps in the future this tool could be integrated on compilation process running build
|
If you run the program without params or incorrect params number
Simple program to generate code to embed files recursivily from a chosen folder.
It will generate a source file with code to embed the files on folder.
More info: https://github.com/jleahred/embed_dir
Usage:
embed_dir <origin-folder> <destiny-file>
where:
origin-folder string is the path to the folder containing the files to embed
destiny-file string is output filename (without .rs extension)
example:
embed_dir src/public src/embed.rs
This will generate a file per directory as:
// autogenerated embed_dir on ...
macro_rules! gen_get_includes_bytes{
($rel_path:expr, $($file:expr),+) => {
pub fn get(file_name: &str) -> Option<&'static [u8]> {
match file_name {
$(
$file => Some(include_bytes!(concat!($rel_path, $file))),
)+
_ => None,
}
}
}
}
gen_get_includes_bytes!("../../test_folder",
"README.adoc",
"Cargo.toml",
"pr/README.adoc"
);The first string on gen_get_includes_bytes! indicates the relative position to files from generated source file.
"../../test_folder",Next strings are the files (they can be nested on folders) embeded.