incdir 1.0.0

Compile-time including of directories.
Documentation
  • Coverage
  • 100%
    2 out of 2 items documented0 out of 1 items with examples
  • Size
  • Source code size: 5.3 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 125.2 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 4s Average build duration of successful builds.
  • all releases: 4s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • htrefil/incdir
    9 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • htrefil

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