1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
//! 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. //! //! ```rust //! #[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 #![deny(missing_docs, missing_copy_implementations, missing_debug_implementations)] #[allow(unused_imports)] #[macro_use] extern crate include_dir_impl; #[macro_use] extern crate proc_macro_hack; extern crate glob; mod dir; mod file; #[cfg(feature = "example")] pub mod generated_example; mod globs; pub use dir::Dir; pub use file::File; #[doc(hidden)] pub use include_dir_impl::*; proc_macro_expr_decl! { include_dir! => include_dir_impl } // for use with `cargo expand >> src/generated_example.rs` //pub static INCLUDE_DIR_SRC: Dir = include_dir!(".");