8 releases

0.2.1 Jun 6, 2018
0.2.0 Jun 6, 2018
0.1.5 Feb 9, 2018
0.1.4 Sep 23, 2017
0.1.3 Jun 10, 2017

#60 in Development tools

Download history 34/week @ 2018-11-17 42/week @ 2018-11-24 54/week @ 2018-12-01 22/week @ 2018-12-08 84/week @ 2018-12-15 32/week @ 2018-12-22 22/week @ 2018-12-29 40/week @ 2019-01-05 19/week @ 2019-01-12 124/week @ 2019-01-19 97/week @ 2019-01-26 39/week @ 2019-02-02 110/week @ 2019-02-09 104/week @ 2019-02-16 180/week @ 2019-02-23

672 downloads per month
Used in 8 crates (5 directly)

MIT license

69KB
812 lines


lib.rs:

An extension to the include_str!() macro for embedding an entire directory tree into your binary.

Examples

The include_dir!() macro will include a directory relative to the project root (using the CARGO_MANIFEST_DIR variable), in this example the source code for the include_dir crate has been included inside itself.

#[macro_use]
extern crate include_dir;

use include_dir::Dir;
use std::path::Path;

const PROJECT_DIR: Dir = include_dir!(".");

# fn main() {
// of course, you can retrieve a file by its full path
let lib_rs = PROJECT_DIR.get_file("src/lib.rs").unwrap();

// you can also inspect the file's contents
let body = lib_rs.contents_utf8().unwrap();
assert!(body.contains("SOME_INTERESTING_STRING"));

// you can search for files (and directories) using glob patterns
let glob = "**/*.rs";
for entry in PROJECT_DIR.find(glob).unwrap() {
    println!("Found {}", entry.path().display());
}
# }

Features

This library exposes a couple feature flags for enabling and disabling extra functionality. These are:

  • example: compile in an example of the embedded directory tree

Dependencies

~1MB
~27K SLoC