#include #tree #directory #build #static

build includedir_codegen

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

7 releases (4 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.2.1 Feb 20, 2016

#942 in Filesystem

Download history 1910/week @ 2023-07-20 1937/week @ 2023-07-27 2084/week @ 2023-08-03 2029/week @ 2023-08-10 2496/week @ 2023-08-17 2623/week @ 2023-08-24 2703/week @ 2023-08-31 1849/week @ 2023-09-07 2093/week @ 2023-09-14 1290/week @ 2023-09-21 1028/week @ 2023-09-28 1683/week @ 2023-10-05 2044/week @ 2023-10-12 2258/week @ 2023-10-19 2801/week @ 2023-10-26 1772/week @ 2023-11-02

9,222 downloads per month
Used in 65 crates (13 directly)

BSD-3-Clause

8KB
142 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

~0.8–1.1MB
~16K SLoC