-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Include only files matching a glob #81
Comments
Do you have an idea of what this might look like from a consumer's point of view? |
I'd think that ideally, it would be inspired by the gitignore syntax. include_dir!(
"$CARGO_MANIFEST_DIR/assets/*", # include all files in assets folder
"!$CARGO_MANIFEST_DIR/assets/.cache" # except .cache folder
"$CARGO_MANIFEST_DIR/images/*.png" # include PNG images from here
); |
I have a similar requirement, I actually just need to include files matching a glob as a Vec of Strings. |
After having encountered this problem of picking a subtree from a directory multiple times, there are two things I'd recommend for a good API.
Let's take an example. The code below prints all the Rust files in the current project: static PROJECT_DIR: Dir = include_dir!("$CARGO_MANIFEST_DIR");
for entry in PROJECT_DIR.find("**/*.rs").unwrap() {
println!("Found {}", entry.path().display());
} This is a prime candidate to apply filtering at inclusion time. Following the points above, I'd recommend the following API with an optional static PROJECT_DIR_ONLY_RUST: Dir = include_dir!("$CARGO_MANIFEST_DIR", filter = "**/*.rs");
// This `find` is only a simple traversal of what's embedded, no filtering occurs at runtime
for entry in PROJECT_DIR_ONLY_RUST.find("**/*").unwrap() {
println!("Found {}", entry.path().display()); // Same output as the previous program
} Notice how the code above is close to the original. You can simply think of it as moving the runtime glob matching to compile time. Further extensions may allow an array as the list of filters, but for the moment I'd recommend to start simply with a single pattern and make sure it works fine. Adding support for a list of multiple patterns requires a bit of care. In general I agree that the best semantics should be to follow how |
I use this crate for packaging serialized 'resource' files in various formats, so being able to include only the applicable formats (as controlled by my crate's features) would be excellent! |
It would be great if we could include just the files matching a particular glob. This is similar to #13, but I think a glob design would be far easier to use.
The text was updated successfully, but these errors were encountered: