#directory #embedding #macro #include #content

macro embeddir

A macro for embedding all files in a directory into the executable

2 releases

0.1.1 Jan 2, 2020
0.1.0 Jan 2, 2020

#1123 in Procedural macros

MIT license

5KB

embeddir

Crates.io

A macro that embeds all files in a specified directory into the executable at compile-time.

Works similarly to include_bytes! macro.

Usage example

#![feature(proc_macro_hygiene)]

fn main() {
	let dir = embeddir::embed!("examples/static");

	for (filename, contents) in &dir {
		println!("Filename: {}, Contents: \"{}\"",
        filename,
        std::str::from_utf8(contents).unwrap());
	}
}

lib.rs:

A simple crate for embedding all files in a directory into the executable.

Works similarly to std::include_bytes! macro.

For this macro to work, you must have proc_macro_hygiene feature enabled.

#![feature(proc_macro_hygiene)]

The files in the directory are not searched recursively, so if you have a directory tree like this:

Dir1/
├──File1
├──File2
└──Dir2/
   └──File3

And specify the Dir1 directory to look for files in, File1 and File2 will be embedded into your executable but File3 will not.

Dependencies

~1.5MB
~32K SLoC