8 releases
0.3.2 | Apr 23, 2020 |
---|---|
0.3.1 | Apr 12, 2020 |
0.3.0 | Feb 29, 2020 |
0.2.2 | Feb 27, 2020 |
0.1.1 | Feb 23, 2020 |
#3 in #include-str
10KB
174 lines
include_walk
Include content files directory recursively using include_str!
or include_bytes!
.
It generate an output rust file with a method that return an HashMap composed like this : <path file &'static str
, content file &'static str
>
Installation
Add include_walk
to the build-dependencies in ./Cargo.toml
.
[build-dependencies]
include_walk = "0.3.0"
Create a builder file ./build.rs
. Below, there is a lite example : that import recursively all file present in ./src/assets/
and
generate a file import ./src/assets.rs
.
By defaults, files are imported as &'static str
using include_str!
.
// ./build.rs
fn main() {
include_walk::from("./src/assets/").to("./src/assets.rs");
}
Use Cases
Retrieve all content files. For more detail see your generated file :
./src/assets.rs
in that example. So include module assets
as the following example.
// ./src/main.rs
mod assets;
fn main() {
let assets = assets::get_all();
let content = assets.get("assets/relative/path/to/files...").unwrap();
println!("{}", content);
}
Methods
Methods | Required | Default | Description |
---|---|---|---|
::from(path) | YES | - | Specified the directory path to import |
.to(path) | YES | - | The path of generated module. |
.filter(|path_file| -> bool) | NO | deactivate | Filter function that take a callback who can provide an path_file PathBuf argument and return bool : true for include and false for exclude file. |
.bytes() | NO | deactivated | include with include_bytes! |
.str() | NO | activated | include with include_str! |
Dependencies
~0.1–7MB
~40K SLoC