Include a whole directory tree at compile time
Last updated Sep 29, 2025
81
Stars
8
Forks
5
Issues
0
Stars/day
Attention Score
10
Language breakdown
Rust 100.0%
โธ Files
click to expand
README
includedir ===========
Include a directory in your Rust binary, e.g. static files for your web server or assets for your game.
Features
- [x] Automatically compile data into binary
- [x] Use rust-phf for efficient lookup
- [x] Wrapping API around the phf map, to abstract away additional features
- [x] Compression, with optional crate "flate2"
- [x] Reading from source files for debug builds
Example
Cargo.toml
[package] name = "example" version = "0.1.0"
build = "build.rs" include = ["data"]
[dependencies] phf = "0.8.0" includedir = "0.6.0"
[build-dependencies] includedir_codegen = "0.6.0"
build.rs
extern crate includedir_codegen;
use includedir_codegen::Compression;
fn main() { includedir_codegen::start("FILES") .dir("data", Compression::Gzip) .build("data.rs") .unwrap(); }
src/main.rs
extern crate includedir;
extern crate phf;
use std::env;
include!(concat!(env!("OUT_DIR"), "/data.rs"));
fn main() { FILES.setpassthrough(env::varos("PASSTHROUGH").is_some());
println!("{:?}", FILES.get("data/foo")) }
๐ More in this category