Michael-F-Bryan / include_dir

The logical evolution of the include_str macro for embedding a directory tree into your binary.
https://michael-f-bryan.github.io/include_dir
MIT License
319 stars 36 forks source link

`include_dir` macro cannot be used when re-exported #87

Closed jjant closed 1 year ago

jjant commented 1 year ago

As I mentioned in #86, I tried to create my own crate which wraps include_dir to add specific behavior that I need. When trying to do this, I noticed that apparently the macro can't really be re-exported:

// mycrate/lib.rs
// depends on include_dir
pub use include_dir;

// mybincrate/main.rs
// depends on mycrate, not on include_dir
fn main() {
  let dir = mycrate::include_dir::include_dir("..."); // ERR: use of undeclared module include_dir
}

I believe this SO gives a possible solution: https://stackoverflow.com/questions/70457235/how-to-reexpose-an-entire-crate-inline.

Michael-F-Bryan commented 1 year ago

If you are wrapping the include_dir!() macro with your own, would something like this work?

macro_rules! my_include_dir {
  ($path:literal) => {{ 
    use $crate::include_dir;
    $crate::include_dir::include_dir!($path)
  }}
}
jjant commented 1 year ago

That indeed worked, thank you!