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

Can't reproduce README's example (glob feature) #84

Closed Poulpy closed 1 year ago

Poulpy commented 1 year ago

Hello !

I want to list all files under a directory, with glob. I tried reproducing the README's example, but the code doesn't seem to run inside the block (I checked with a println!()), the one with the feature glob enabled.

I did that :

use include_dir::{Dir, include_dir};

static SPEC_DIR: Dir<'_> = include_dir!("resources/spec");

fn main() {
    #[cfg(feature = "glob")]
    {
        let glob = "v2.3/messages/*.xsd";
        for entry in SPEC_DIR.find(glob).unwrap() {
            println!("Found {}", entry.path().display());
        }
    }
}

Is there anything wrong with my code ?

Thank you !

Edit: I'm using include_dir's version 0.7.2

Michael-F-Bryan commented 1 year ago

The #[cfg(feature = "glob")] is an attribute which only compiles the code within the block when the glob feature is enabled in your Cargo.toml. It's what include_dir uses to let people opt into the extra glob functionality.

You probably want to remove the block and attribute, and make sure your Cargo.toml looks something like this:

[dependencies]
include_dir = { version = "^0.7.2", features = ["glob"] }
Poulpy commented 1 year ago

Thank you it works ! That was a silly error ^^' Thanks a lot :D !