Skip to content
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

Make Glob.literal() a public function #2946

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

orf
Copy link

@orf orf commented Dec 9, 2024

Being able to detect if a given string is a glob expression or a literal string is very handy in some contexts.

As on example, we have a list of default AWS regions that we allow the user to specify a glob expression to match. However, the user may want to include another custom string as a region.

Detecting if the user has passed a glob expression or a literal string is currently not possible with this crate, which is a real shame. If literal() was public then the implementation above would be as simple as:

let globs: &[Glob] = ...;
let glob_set = GlobSet::builder().add(...);
let literal_regions = globs.iter().filter_map(|g| g.literal());
let matched_regions = DEFAULT_REGIONS.iter().filter(|region| glob_set.is_match(region));

return literal_regions.chain(matched_regions).collect();

I think that exposing the full AST or any specific internals is a bad idea, but being able to tell if a glob is a literal string is non-invasive (and simple!) enough to warrant exposing?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant