pub struct Builder<'a> { /* private fields */ }Expand description
A builder for a matcher or globs.
This builder can be configured to match case sensitive (default) or case insensitive.
A single asterisk will not match path separators, e.g., */*.txt does not match the file
path/to/file.txt. Use ** to match across directory boundaries.
The lifetime 'a refers to the lifetime of the glob string.
Implementations§
Source§impl<'a> Builder<'a>
impl<'a> Builder<'a>
Sourcepub fn new(glob: &'a str) -> Builder<'a>
pub fn new(glob: &'a str) -> Builder<'a>
Create a new builder for the given glob.
The glob is not compiled until any of the build methods is called.
Sourcepub fn case_sensitive(&mut self, yes: bool) -> &mut Builder<'a>
pub fn case_sensitive(&mut self, yes: bool) -> &mut Builder<'a>
Toggle whether the glob matches case sensitive or not.
The default setting is to match case sensitive.
Sourcepub fn build<P>(&self, root: P) -> Result<Matcher<'a, PathBuf>, String>
pub fn build<P>(&self, root: P) -> Result<Matcher<'a, PathBuf>, String>
Builds a Matcher for the given Builder relative to root.
Resolves the relative path prefix for the glob that has been provided when creating the
builder for the given root directory, e.g.,
For the root directory /path/to/some/folder and glob ../../*.txt, this function will
move the relative path components to the root folder, resulting in only *.txt for the
glob, and /path/to/some/folder/../../ for the root directory.
Notice that the relative path components will not be resolved. The caller of the function can map and consolidate each path yielded by the iterator, if required.
§Errors
Simple error messages will be provided in case of failures, e.g., for empty patterns or patterns for which the compilation failed; as well as for invalid root directories.
Sourcepub fn build_glob(&self) -> Result<Glob<'a>, String>
pub fn build_glob(&self) -> Result<Glob<'a>, String>
Sourcepub fn build_glob_set(&self) -> Result<GlobSet<'a>, String>
pub fn build_glob_set(&self) -> Result<GlobSet<'a>, String>
Builds a combined GlobSet.
A globset extends the provided pattern to [pattern, **/pattern]. This is useful, e.g.,
for blacklists, where only the file type is important.
Yes, it would be sufficient to use the pattern **/pattern in the first place. This is
a simple commodity function.