Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
[workspace]
resolver = "2"
members = ["include_dir", "macros"]
8 changes: 4 additions & 4 deletions include_dir/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
authors = ["Michael Bryan <[email protected]>"]
name = "include_dir"
name = "comfy_include_dir"
version = "0.7.3"
description = "Embed the contents of a directory in your binary"
license = "MIT"
Expand All @@ -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
2 changes: 1 addition & 1 deletion include_dir/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
2 changes: 1 addition & 1 deletion macros/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>"]
Expand Down
33 changes: 28 additions & 5 deletions macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<Vec<_>>();

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::<Vec<_>>();

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::<String>();

let path = resolve_path(&path, get_env).unwrap();

Expand Down