#directory #build #include #static #tree

includedir

Include a whole directory tree at compile time! - Runtime part

9 releases (5 breaking)

Uses old Rust 2015

0.6.0 May 27, 2020
0.5.0 Dec 14, 2018
0.4.0 Apr 9, 2018
0.3.0 Mar 12, 2018
0.1.1 Feb 16, 2016

#1258 in Filesystem

Download history 1528/week @ 2025-08-13 1737/week @ 2025-08-20 2420/week @ 2025-08-27 1916/week @ 2025-09-03 2161/week @ 2025-09-10 1601/week @ 2025-09-17 2401/week @ 2025-09-24 1026/week @ 2025-10-01 1759/week @ 2025-10-08 1688/week @ 2025-10-15 1840/week @ 2025-10-22 1912/week @ 2025-10-29 2608/week @ 2025-11-05 2222/week @ 2025-11-12 3320/week @ 2025-11-19 2180/week @ 2025-11-26

10,718 downloads per month
Used in 75 crates (13 directly)

BSD-3-Clause

6KB
90 lines

includedir

Travis Appveyor Crates.io version docs.rs Crates.io license

Include a directory in your Rust binary, e.g. static files for your web server or assets for your game.

Features

  • Automatically compile data into binary
  • Use rust-phf for efficient lookup
  • Wrapping API around the phf map, to abstract away additional features
  • Compression, with optional crate "flate2"
  • 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.set_passthrough(env::var_os("PASSTHROUGH").is_some());

    println!("{:?}", FILES.get("data/foo"))
}

Dependencies

~435KB