Struct jwalk::WalkDirGeneric
source · pub struct WalkDirGeneric<C: ClientState> { /* private fields */ }
Expand description
Generic builder for walking a directory.
ClientState
type parameter allows you to specify
state to be stored with each DirEntry from within the
process_read_dir
callback.
Use WalkDir
if you don’t need to store client state
into yeilded DirEntries.
Implementations§
source§impl<C: ClientState> WalkDirGeneric<C>
impl<C: ClientState> WalkDirGeneric<C>
sourcepub fn new<P: AsRef<Path>>(root: P) -> Self
pub fn new<P: AsRef<Path>>(root: P) -> Self
Create a builder for a recursive directory iterator starting at the file path root. If root is a directory, then it is the first item yielded by the iterator. If root is a file, then it is the first and only item yielded by the iterator.
Note that his iterator can fail on the first element if into_iter()
is used as it
has to be infallible. Use try_into_iter()
instead for error handling.
sourcepub fn try_into_iter(self) -> Result<DirEntryIter<C>>
pub fn try_into_iter(self) -> Result<DirEntryIter<C>>
Try to create an iterator or fail if the rayon threadpool (in any configuration) is busy.
sourcepub fn sort(self, sort: bool) -> Self
pub fn sort(self, sort: bool) -> Self
Sort entries by file_name
per directory. Defaults to false
. Use
process_read_dir
for custom
sorting or filtering.
Skip hidden entries. Enabled by default.
sourcepub fn follow_links(self, follow_links: bool) -> Self
pub fn follow_links(self, follow_links: bool) -> Self
Follow symbolic links. By default, this is disabled.
When yes
is true
, symbolic links are followed as if they were normal
directories and files. If a symbolic link is broken or is involved in a
loop, an error is yielded.
When enabled, the yielded DirEntry
values represent the target of
the link while the path corresponds to the link. See the DirEntry
type for more details.
sourcepub fn min_depth(self, depth: usize) -> Self
pub fn min_depth(self, depth: usize) -> Self
Set the minimum depth of entries yielded by the iterator.
The smallest depth is 0
and always corresponds to the path given
to the new
function on this type. Its direct descendents have depth
1
, and their descendents have depth 2
, and so on.
sourcepub fn max_depth(self, depth: usize) -> Self
pub fn max_depth(self, depth: usize) -> Self
Set the maximum depth of entries yield by the iterator.
The smallest depth is 0
and always corresponds to the path given
to the new
function on this type. Its direct descendents have depth
1
, and their descendents have depth 2
, and so on.
A depth < 2 will automatically change parallelism
to
Parallelism::Serial
. Parrallelism happens at the fs::read_dir
level.
It only makes sense to use multiple threads when reading more then one
directory.
Note that this will not simply filter the entries of the iterator, but it will actually avoid descending into directories when the depth is exceeded.
sourcepub fn parallelism(self, parallelism: Parallelism) -> Self
pub fn parallelism(self, parallelism: Parallelism) -> Self
Degree of parallelism to use when performing walk. Defaults to
Parallelism::RayonDefaultPool
.
sourcepub fn root_read_dir_state(self, read_dir_state: C::ReadDirState) -> Self
pub fn root_read_dir_state(self, read_dir_state: C::ReadDirState) -> Self
Initial ClientState::ReadDirState that is passed to
process_read_dir
when processing root. Defaults to ClientState::ReadDirState::default().
sourcepub fn process_read_dir<F>(self, process_by: F) -> Selfwhere
F: Fn(Option<usize>, &Path, &mut C::ReadDirState, &mut Vec<Result<DirEntry<C>>>) + Send + Sync + 'static,
pub fn process_read_dir<F>(self, process_by: F) -> Selfwhere
F: Fn(Option<usize>, &Path, &mut C::ReadDirState, &mut Vec<Result<DirEntry<C>>>) + Send + Sync + 'static,
A callback function to process (sort/filter/skip/state) each directory
of entries before they are yielded. Modify the given array to
sort/filter entries. Use entry.read_children_path = None
to yield a
directory entry but skip reading its contents. Use
entry.client_state
to store custom state with an entry.