Skip to content

axos88/includedir

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

33 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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
  • Tested on non-Linux platforms. Passthrough won't work on Windows, the rest should.

Example

Cargo.toml

[package]
name = "example"
version = "0.1.0"

build = "build.rs"
include = ["data"]

[dependencies]
phf = "0.7.21"
includedir = "0.4.0"

[build-dependencies]
includedir_codegen = "0.4.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"))
}

About

Include a whole directory tree at compile time

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Rust 100.0%