Builder

Struct Builder 

Source
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>

Source

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.

Source

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.

Source

pub fn build<P>(&self, root: P) -> Result<Matcher<'a, PathBuf>, String>
where P: AsRef<Path>,

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.

Source

pub fn build_glob(&self) -> Result<Glob<'a>, String>

Builds a Glob.

This Glob that can be used for filtering paths provided by a Matcher (created using the build function).

Source

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.

Trait Implementations§

Source§

impl<'a> Debug for Builder<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for Builder<'a>

§

impl<'a> RefUnwindSafe for Builder<'a>

§

impl<'a> Send for Builder<'a>

§

impl<'a> Sync for Builder<'a>

§

impl<'a> Unpin for Builder<'a>

§

impl<'a> UnwindSafe for Builder<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.