Embed a directory tree using include_dir!
masterThe include_dir! macro allows you to embed an entire directory tree into your binary at compile time. It functions similarly to the standard include_str! and include_bytes! macros. You provide a file path to the macro and assign the resulting Dir to a static variable.
Once embedded, you can use the Dir object to retrieve files by their full path, inspect their contents, or search for them using glob patterns (if the glob feature is enabled).
use include_dir::{include_dir, Dir};
static PROJECT_DIR: Dir = include_dir!("$CARGO_MANIFEST_DIR");
// Retrieve a file by its full path
let lib_rs = PROJECT_DIR.get_file("src/lib.rs").unwrap();
// Inspect file contents as UTF-8
let body = lib_rs.contents_utf8().unwrap();