diff --git a/Cargo.toml b/Cargo.toml index b2b10a9da9..732a4b7581 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,2 +1,3 @@ [workspace] +resolver = "2" members = ["include_dir", "macros"] diff --git a/include_dir/Cargo.toml b/include_dir/Cargo.toml index fc09154a0a..741d8a4f1b 100644 --- a/include_dir/Cargo.toml +++ b/include_dir/Cargo.toml @@ -1,6 +1,6 @@ [package] authors = ["Michael Bryan "] -name = "include_dir" +name = "comfy_include_dir" version = "0.7.3" description = "Embed the contents of a directory in your binary" license = "MIT" @@ -13,15 +13,15 @@ rust-version = "1.56" [dependencies] glob = { version = "0.3", optional = true } -include_dir_macros = { version = "^0.7.0", path = "../macros" } +comfy_include_dir_macros = { version = "^0.7.0", path = "../macros" } [dev-dependencies] tempfile = "3" [features] default = [] -nightly = ["include_dir_macros/nightly"] -metadata = ["include_dir_macros/metadata"] +nightly = ["comfy_include_dir_macros/nightly"] +metadata = ["comfy_include_dir_macros/metadata"] [package.metadata.docs.rs] all-features = true diff --git a/include_dir/src/lib.rs b/include_dir/src/lib.rs index b9380b931c..3567e124d6 100644 --- a/include_dir/src/lib.rs +++ b/include_dir/src/lib.rs @@ -104,7 +104,7 @@ mod globs; pub use crate::metadata::Metadata; pub use crate::{dir::Dir, dir_entry::DirEntry, file::File}; -pub use include_dir_macros::include_dir; +pub use comfy_include_dir_macros::include_dir; #[doc = include_str!("../README.md")] #[allow(dead_code)] diff --git a/macros/Cargo.toml b/macros/Cargo.toml index 3ce97c9e20..6418c31d40 100644 --- a/macros/Cargo.toml +++ b/macros/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "include_dir_macros" +name = "comfy_include_dir_macros" version = "0.7.3" description = "The procedural macro used by include_dir" authors = ["Michael Bryan "] diff --git a/macros/src/lib.rs b/macros/src/lib.rs index 51e5b4cf49..986039e214 100644 --- a/macros/src/lib.rs +++ b/macros/src/lib.rs @@ -16,12 +16,35 @@ use std::{ /// Embed the contents of a directory in your crate. #[proc_macro] pub fn include_dir(input: TokenStream) -> TokenStream { - let tokens: Vec<_> = input.into_iter().collect(); + let literals = input + .into_iter() + .map(|token| match token { + TokenTree::Literal(lit) => lit, + TokenTree::Group(ref group) => { + let inside = group.stream().into_iter().collect::>(); + + if let [TokenTree::Literal(lit)] = inside.as_slice() { + lit.clone() + } else { + panic!( + "This macro only accepts string arguments, got unexpected {:?}", + token + ); + } + } + _ => { + panic!( + "This macro only accepts string arguments, got unexpected {:?}", + token + ); + } + }) + .collect::>(); - let path = match tokens.as_slice() { - [TokenTree::Literal(lit)] => unwrap_string_literal(lit), - _ => panic!("This macro only accepts a single, non-empty string argument"), - }; + let path = literals + .into_iter() + .map(|lit| unwrap_string_literal(&lit)) + .collect::(); let path = resolve_path(&path, get_env).unwrap();