incdir

Crates.ioincdir
lib.rsincdir
version1.0.0
sourcesrc
created_at2020-01-02 16:51:35.746222
updated_at2020-01-05 15:01:53.089775
descriptionCompile-time including of directories.
homepage
repositoryhttps://github.com/htrefil/incdir
max_upload_size
id194536
size5,317
htrefil (htrefil)

documentation

README

incdir

Documentation

Compile-time including of directories.

This crate works in a similar fashion as the include_bytes! macro in Rust, except it includes a whole directory and stores them in a perfect hash function map from the phf crate.
For cross-platform consistency, backslashes in paths stored in the map are replaced with forward slashes.

All pathnames in the directory processed by the include_dir! macro must be valid UTF-8.

Usage

[dependencies]
incdir = "1.0.0"
phf = { version = "*", features = ["macros"] }
#![feature(proc_macro_hygiene)]
use phf::Map;

static TEXTURES: Map<&'static str, &'static [u8]> = incdir::include_dir!("textures");

fn main() {
    // The file is stored in "files/player.png", the directory prefix is stripped in the map.
    let player = TEXTURES.get("player.png").unwrap();
    // Stored in "textures/world/grass.png".
    let grass = TEXTURES.get("world/grass.png").unwrap()
}

License

MIT

Commit count: 18

cargo fmt