pub struct WalkOptions { /* private fields */ }Expand description
Structure encoding the desired walking options
§Example
use fs_walk;
let o = fs_walk::WalkOptions::new()
// we want to walk only files
.files()
// we want files with .o extension
.extension("o");
assert!(o.walk("./").count() > 0);Implementations§
Source§impl WalkOptions
impl WalkOptions
Sourcepub fn new() -> Self
pub fn new() -> Self
Create default walking options. The default behaviour is to return both files and directories.
§Example
use fs_walk;
use std::path::PathBuf;
let o = fs_walk::WalkOptions::new();
let paths: Vec<PathBuf> = o.walk("./").flatten().collect();
assert!(paths.iter().any(|p| p.is_dir()));
assert!(paths.iter().any(|p| p.is_file()));Sourcepub fn dirs(self) -> Self
pub fn dirs(self) -> Self
Configure walking option to return only directories
§Example
use fs_walk;
let o = fs_walk::WalkOptions::new()
.dirs();
for p in o.walk("./").flatten() {
assert!(p.is_dir());
}Sourcepub fn files(self) -> Self
pub fn files(self) -> Self
Configure walking option to return only files
§Example
use fs_walk;
let o = fs_walk::WalkOptions::new()
.files();
for p in o.walk("./").flatten() {
assert!(p.is_file());
}Sourcepub fn max_depth(self, depth: u64) -> Self
pub fn max_depth(self, depth: u64) -> Self
Configure a maximum depth for the walker. If no depth is specified the walker will walk through all directories in a BFS way.
§Example
use fs_walk;
use std::path::Path;
let o = fs_walk::WalkOptions::new()
.max_depth(0);
for p in o.walk("./").flatten() {
assert_eq!(p.parent(), Some(Path::new(".")));
}
Sourcepub fn extension<S: AsRef<str>>(self, ext: S) -> Self
pub fn extension<S: AsRef<str>>(self, ext: S) -> Self
Configure walker to return only files matching file extension.
For any file, if Path::extension is not None it will be
checked against ext. This function can be called several
times to return files matching one of the desired extension.
See Path::extension for the correct way to specify ext.
§Example
use fs_walk;
use std::path::PathBuf;
use std::ffi::OsStr;
let o = fs_walk::WalkOptions::new()
.files()
.extension("o")
.extension("rs");
let paths: Vec<PathBuf> = o.walk("./").flatten().collect();
assert!(paths.iter().any(|p| p.extension() == Some(OsStr::new("o"))));
assert!(paths.iter().any(|p| p.extension() == Some(OsStr::new("rs"))));
assert!(!paths.iter().any(|p| p.extension() == Some(OsStr::new("toml"))));
assert!(!paths.iter().any(|p| p.extension() == Some(OsStr::new("lock"))));Trait Implementations§
Source§impl Clone for WalkOptions
impl Clone for WalkOptions
Source§fn clone(&self) -> WalkOptions
fn clone(&self) -> WalkOptions
Returns a copy of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for WalkOptions
impl Debug for WalkOptions
Source§impl Default for WalkOptions
impl Default for WalkOptions
Source§fn default() -> WalkOptions
fn default() -> WalkOptions
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for WalkOptions
impl RefUnwindSafe for WalkOptions
impl Send for WalkOptions
impl Sync for WalkOptions
impl Unpin for WalkOptions
impl UnwindSafe for WalkOptions
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit)