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 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
//! The logical evolution of the `include_str!()` macro to allow embedding //! entire file trees. //! //! If you want to use this in stable, you'll need a `build.rs` build script. //! //! ```rust,no_run //! extern crate include_dir; //! //! use std::env; //! use std::path::Path; //! use include_dir::include_dir; //! //! fn main() { //! let outdir = env::var("OUT_DIR").unwrap(); //! let dest_path = Path::new(&outdir).join("assets.rs"); //! //! include_dir("assets") //! .as_variable("SRC") //! .to_file(dest_path) //! .unwrap(); //! } //! ``` //! //! Then in one of your source files, you'll need to include the generated //! `assets.rs` file. Notice that it's been included as a submodule, that //! way the code `include_dir` generates won't pollute the rest of your project. //! By making it public, you also gain the ability to check out the generated //! assets and see what you can do with them. //! //! ```rust,ignore //! #[allow(dead_code)] //! pub mod assets { //! include!(concat!(env!("OUT_DIR"), "/assets.rs")); //! } //! ``` //! //! # Note //! //! Because a large part of this crate's functionality comes from code //! generation, the best reference for features and examples will be the //! [integration tests] directory. //! //! //! # Features //! //! By default `include_dir` requires no extra runtime dependencies. This is //! great because you just need to run the build script and include the //! generated file and then have full access access to the embedded assets, //! however it does limit your ability to access some nice features. //! //! ## Glob Search //! //! This feature adds the ability to search for files using glob patterns. It //! requires you to add `extern crate glob` to the top of your `lib.rs` or ' //! `main.rs`, and is accessible using the `globs` feature flag. //! //! ```rust,ignore //! extern crate glob; //! //! for entry in ASSETS.glob("*.rs")? { //! println!("{}", entry.path().display()); //! } //! ``` //! //! [integration tests]: https://github.com/Michael-F-Bryan/include_dir/tree/master/integration_tests #![deny(missing_docs, missing_debug_implementations, missing_copy_implementations, trivial_casts, trivial_numeric_casts, unsafe_code, unused_import_braces, unused_qualifications)] #[macro_use] extern crate error_chain; extern crate glob; #[cfg(test)] extern crate tempfile; #[cfg(test)] extern crate tempdir; mod files; mod helpers; mod dirs; mod serializer; mod frontend; pub use frontend::{include_dir, IncludeDirBuilder}; /// Submodule containing code generated by `error-chain`. pub mod errors { error_chain!{ foreign_links { IO(::std::io::Error) #[doc = "A wrapper around a std::io::Error"]; StripPath(::std::path::StripPrefixError) #[doc = "A wrapper around a strip prefix error"]; } } }