Skip to content

Include directory recursively using include_str! or include_bytes!

Notifications You must be signed in to change notification settings

vincent-herlemont/include_walk

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

include_walk

Crate Rust

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!

About

Include directory recursively using include_str! or include_bytes!

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages