include_dir_impl-0.5.0/Cargo.toml.orig010064400017500001750000000011051360711136200161230ustar0000000000000000[package] authors = ["Michael Bryan "] name = "include_dir_impl" version = "0.5.0" description = "Implementation crate for include_dir" license = "MIT" readme = "../README.md" repository = "https://github.com/Michael-F-Bryan/include_dir" edition = "2018" [badges.appveyor] branch = "master" repository = "Michael-F-Bryan/include-dir" service = "github" [badges.travis-ci] branch = "master" repository = "Michael-F-Bryan/include_dir" [dependencies] proc-macro-hack = "0.5" syn = "1" quote = "1" failure = "0.1" proc-macro2 = "1" [lib] proc-macro = true include_dir_impl-0.5.0/Cargo.toml0000644000000022701360711136400124370ustar00# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO # # When uploading crates to the registry Cargo will automatically # "normalize" Cargo.toml files for maximal compatibility # with all versions of Cargo and also rewrite `path` dependencies # to registry (e.g., crates.io) dependencies # # If you believe there's an error in this file please file an # issue against the rust-lang/cargo repository. If you're # editing this file be aware that the upstream Cargo.toml # will likely look very different (and much more reasonable) [package] edition = "2018" name = "include_dir_impl" version = "0.5.0" authors = ["Michael Bryan "] description = "Implementation crate for include_dir" readme = "../README.md" license = "MIT" repository = "https://github.com/Michael-F-Bryan/include_dir" [lib] proc-macro = true [dependencies.failure] version = "0.1" [dependencies.proc-macro-hack] version = "0.5" [dependencies.proc-macro2] version = "1" [dependencies.quote] version = "1" [dependencies.syn] version = "1" [badges.appveyor] branch = "master" repository = "Michael-F-Bryan/include-dir" service = "github" [badges.travis-ci] branch = "master" repository = "Michael-F-Bryan/include_dir" include_dir_impl-0.5.0/src/dir.rs010064400017500001750000000033151360710757400151660ustar0000000000000000use crate::file::File; use failure::{self, Error, ResultExt}; use proc_macro2::TokenStream; use quote::{quote, ToTokens}; use std::path::{Path, PathBuf}; #[derive(Debug, Clone, PartialEq)] pub(crate) struct Dir { root_rel_path: PathBuf, abs_path: PathBuf, files: Vec, dirs: Vec, } impl Dir { pub fn from_disk, P: Into>(root: Q, path: P) -> Result { let abs_path = path.into(); let root = root.as_ref(); let root_rel_path = abs_path.strip_prefix(&root).unwrap().to_path_buf(); if !abs_path.exists() { return Err(failure::err_msg("The directory doesn't exist")); } let mut files = Vec::new(); let mut dirs = Vec::new(); for entry in abs_path.read_dir().context("Couldn't read the directory")? { let entry = entry?.path(); if entry.is_file() { files.push(File::from_disk(&root, entry)?); } else if entry.is_dir() { dirs.push(Dir::from_disk(&root, entry)?); } } Ok(Dir { root_rel_path, abs_path, files, dirs, }) } } impl ToTokens for Dir { fn to_tokens(&self, tokens: &mut TokenStream) { let root_rel_path = self.root_rel_path.display().to_string(); let files = &self.files; let dirs = &self.dirs; let tok = quote! { $crate::Dir { path: #root_rel_path, files: &[#( #files ),*], dirs: &[#( #dirs ),*], } }; tok.to_tokens(tokens); } } include_dir_impl-0.5.0/src/file.rs010064400017500001750000000017431356003705500153240ustar0000000000000000use failure::Error; use proc_macro2::TokenStream; use quote::{quote, ToTokens}; use std::path::{Path, PathBuf}; #[derive(Debug, Clone, PartialEq)] pub(crate) struct File { root_rel_path: PathBuf, abs_path: PathBuf, } impl File { pub fn from_disk, P: Into>(root: Q, path: P) -> Result { let abs_path = path.into(); let root = root.as_ref(); let root_rel_path = abs_path.strip_prefix(&root).unwrap().to_path_buf(); Ok(File { abs_path, root_rel_path, }) } } impl ToTokens for File { fn to_tokens(&self, tokens: &mut TokenStream) { let root_rel_path = self.root_rel_path.display().to_string(); let abs_path = self.abs_path.display().to_string(); let tok = quote! { $crate::File { path: #root_rel_path, contents: include_bytes!(#abs_path), } }; tok.to_tokens(tokens); } } include_dir_impl-0.5.0/src/lib.rs010064400017500001750000000020121360710757400151470ustar0000000000000000//! Implementation crate for the [include_dir!()] macro. //! //! [include_dir!()]: https://github.com/Michael-F-Bryan/include_dir extern crate failure; extern crate proc_macro; extern crate proc_macro2; extern crate proc_macro_hack; extern crate quote; extern crate syn; use proc_macro::TokenStream; use proc_macro_hack::proc_macro_hack; use quote::quote; use syn::{parse_macro_input, LitStr}; use crate::dir::Dir; use std::env; use std::path::PathBuf; mod dir; mod file; #[proc_macro_hack] pub fn include_dir(input: TokenStream) -> TokenStream { let input: LitStr = parse_macro_input!(input as LitStr); let crate_root = env::var("CARGO_MANIFEST_DIR").unwrap(); let path = PathBuf::from(crate_root).join(input.value()); if !path.exists() { panic!("\"{}\" doesn't exist", path.display()); } let path = path.canonicalize().expect("Can't normalize the path"); let dir = Dir::from_disk(&path, &path).expect("Couldn't load the directory"); TokenStream::from(quote! { #dir }) } include_dir_impl-0.5.0/.cargo_vcs_info.json0000644000000001121360711136400144320ustar00{ "git": { "sha1": "77b531a4b545d729f2f411ba4552a07dadcc926e" } }