Skip to main content

WalkBuilder

Struct WalkBuilder 

Source
pub struct WalkBuilder { /* private fields */ }
Available on crate feature fs only.
Expand description

Builder for a directory Walk, providing a simpler API over the ignore crate for the most common cases.

Created with cu::fs::walker.

Implementations§

Source§

impl WalkBuilder

Source

pub fn as_inner_mut(&mut self) -> &mut IgnoreWalkBuilder

Return the inner WalkBuilder from the ignore crate for advanced configuration. Note that the overrides matcher will be replaced when building the walker

Source

pub fn glob_includes( &mut self, globs: impl IntoIterator<Item = impl AsRef<str>>, ) -> Result<&mut Self>

Add glob patterns to include. By default all paths are included.

Patterns use gitignore-style glob syntax (as implemented by the ignore crate), which supports *, **, ?, [...] character classes, and {a,b} brace alternation. Once any include pattern is added, only paths matching at least one include (and no exclude) are yielded.

§Caution

If the glob pattern starts with ./, the dot is removed instead of matching literal ./. Patterns starting with ../ still matches the literal ../ (meaning the root must start with ../ to produce any match)

let mut walker = cu::fs::walker(".");
// include Rust and TOML files anywhere in the tree
walker.glob_includes(["**/*.{rs,toml}"])?;
for entry in walker.walk()? {
    cu::info!("{}", entry?.path().display());
}
Source

pub fn glob_excludes( &mut self, globs: impl IntoIterator<Item = impl AsRef<str>>, ) -> Result<&mut Self>

Add glob patterns to exclude. By default nothing is excluded.

§Caution

If the glob pattern starts with ./, the dot is removed instead of matching literal ./. Patterns starting with ../ still matches the literal ../ (meaning the root must start with ../ to produce any match)

let mut builder = cu::fs::walker(".");
builder.glob_excludes(["**/*.{log,tmp}"])?;
for entry in builder.walk()? {
    cu::info!("{}", entry?.path().display());
}
Source

pub fn include_dir_entries(&mut self, include: bool) -> &mut Self

Set whether directory entries are returned while iterating. Default is false (only files are yielded).

When enabled, directory entries and symlinks-to-directories are also yielded (as well as the root of the walk, at depth 0). Note that the files inside a symlinked directory are still not returned unless follow_links is also enabled.

Source

pub fn git(&mut self, yes: bool) -> &mut Self

Enable reading .gitignore and git exclude configs, (mostly) matching git’s own behavior. Default is disabled.

Because this relies on git configuration, ignore rules are only applied when the walk root is inside a git repository.

Source

pub fn ignore_hidden(&mut self, yes: bool) -> &mut Self

Skip hidden files. Default is false (i.e. hidden files are included).

Follow symbolic links. Default is false.

Source

pub fn add_ignore_filename(&mut self, ignore_file: &str) -> &mut Self

Add a custom ignore file name (in addition to any enabled by git).

Files with this name are read as gitignore-style ignore lists. Unlike git, custom ignore files are honored regardless of whether the walk root is inside a git repository.

Source

pub fn walk(self) -> Result<Walk>

Build the Walk iterator from this configuration.

Fails if any configured glob patterns cannot be compiled.

Auto Trait Implementations§

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.

§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

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

Source§

type Error = !

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.