### Example: Handling WalkDir Errors Source: https://docs.rs/globwalk/0.9.1/globwalk/type.WalkError.html Demonstrates how to iterate through directory entries using WalkDir and handle potential errors, including accessing the path and inspecting inner IO errors. ```rust use std::io; use std::path::Path; use walkdir::WalkDir; for entry in WalkDir::new("foo") { match entry { Ok(entry) => println!("{}", entry.path().display()), Err(err) => { let path = err.path().unwrap_or(Path::new("")).display(); println!("failed to access entry {}", path); if let Some(inner) = err.io_error() { match inner.kind() { io::ErrorKind::InvalidData => { println!( "entry contains invalid data: {}", inner) } io::ErrorKind::PermissionDenied => { println!( "Missing permission to read entry: {}", inner) } _ => { println!( "Unexpected error occurred: {}", inner) } } } } } } ``` -------------------------------- ### Find image files using glob pattern Source: https://docs.rs/globwalk/0.9.1/src/globwalk/lib.rs.html Use the `glob` function to find files matching a pattern like `*.{png,jpg,gif}`. This example iterates through the results, removing each matched file. Ensure the `globwalk` crate is added as a dependency. ```rust extern crate globwalk; # include!("doctests.rs"); use std::fs; # fn run() -> Result<(), Box> { # let temp_dir = create_files(&["cow.jog", "cat.gif"])?; # ::std::env::set_current_dir(&temp_dir)?; for img in globwalk::glob("*.{png,jpg,gif}")? { if let Ok(img) = img { fs::remove_file(img.path())?; } } # Ok(()) # } # fn main() { run().unwrap() } ``` -------------------------------- ### Advanced globbing with GlobWalkerBuilder Source: https://docs.rs/globwalk/0.9.1/src/globwalk/lib.rs.html Configure recursive file searching with `GlobWalkerBuilder`. This example demonstrates setting multiple patterns (including exclusions), maximum depth, and enabling symbolic link following. The `build()` method creates the walker, which can then be iterated. ```rust extern crate globwalk; # include!("doctests.rs"); use std::fs; # fn run() -> Result<(), Box> { # let temp_dir = create_files(&["cow.jog", "cat.gif"])?; # let BASE_DIR = &temp_dir; let walker = globwalk::GlobWalkerBuilder::from_patterns( BASE_DIR, &["*.{png,jpg,gif}", "!Pictures/*"], ) .max_depth(4) .follow_links(true) .build()? .into_iter() .filter_map(Result::ok); for img in walker { fs::remove_file(img.path())?; } # Ok(()) # } # fn main() { run().unwrap() } ``` -------------------------------- ### Get Defined Flags Source: https://docs.rs/globwalk/0.9.1/globwalk/struct.FileType.html Retrieves the set of defined flags for the FileType. ```APIDOC ## FLAGS ### Description The set of defined flags. ### Constant `FLAGS: &'static [Flag]` ``` -------------------------------- ### Construct GlobWalkerBuilder with a glob pattern Source: https://docs.rs/globwalk/0.9.1/src/globwalk/lib.rs.html Creates a new GlobWalkerBuilder. If the pattern is absolute, it splits the path into a base and a glob pattern. Otherwise, it starts searching from the current directory. ```rust pub fn glob_builder>(pattern: S) -> GlobWalkerBuilder { // Check to see if the pattern starts with an absolute path let path_pattern: PathBuf = pattern.as_ref().into(); if path_pattern.is_absolute() { // If the pattern is an absolute path, split it into the longest base and a pattern. let mut base = PathBuf::new(); let mut pattern = PathBuf::new(); let mut globbing = false; // All `to_str().unwrap()` calls should be valid since the input is a string. for c in path_pattern.components() { let os = c.as_os_str().to_str().unwrap(); for c in &["*", "{", "}"][..] { if os.contains(c) { globbing = true; break; } } if globbing { pattern.push(c); } else { base.push(c); } } let pat = pattern.to_str().unwrap(); if cfg!(windows) { GlobWalkerBuilder::new(base.to_str().unwrap(), pat.replace('\\', "/")) } else { GlobWalkerBuilder::new(base.to_str().unwrap(), pat) } } else { // If the pattern is relative, start searching from the current directory. GlobWalkerBuilder::new(".", pattern) } } ``` -------------------------------- ### GlobWalkerBuilder::build Source: https://docs.rs/globwalk/0.9.1/globwalk/struct.GlobWalkerBuilder.html Finalizes the builder configuration and constructs a `GlobWalker` instance. Returns a `Result` which is `Ok(GlobWalker)` on success or `Err(GlobError)` if an error occurred during setup. ```APIDOC ## GlobWalkerBuilder::build ### Description Finalize and build a `GlobWalker` instance. ### Signature ```rust pub fn build(self) -> Result ``` ``` -------------------------------- ### Consume DirEntry to Get Full Path Source: https://docs.rs/globwalk/0.9.1/globwalk/type.DirEntry.html Consumes the DirEntry to return ownership of the full path. This is analogous to the `path` method but moves ownership. ```rust pub fn into_path(self) -> PathBuf ``` -------------------------------- ### Get File Type for DirEntry Source: https://docs.rs/globwalk/0.9.1/globwalk/type.DirEntry.html Returns the file type for the file pointed to by the DirEntry. If the entry is a symbolic link and `follow_links` is true, this returns the target's type. This method does not make system calls. ```rust pub fn file_type(&self) -> FileType ``` -------------------------------- ### Get Metadata for DirEntry Source: https://docs.rs/globwalk/0.9.1/globwalk/type.DirEntry.html Retrieves the metadata for the file pointed to by the DirEntry. This follows symbolic links if `follow_links` is enabled in `WalkDir`. Platform behavior notes that `std::fs::symlink_metadata` is called, but `std::fs::metadata` is used if the entry is a symbolic link and `follow_links` is enabled. ```rust pub fn metadata(&self) -> Result ``` -------------------------------- ### Error Trait: Description Method Source: https://docs.rs/globwalk/0.9.1/globwalk/type.WalkError.html Provides a deprecated method to get a string description of the error. It is recommended to use the Display implementation or `to_string()` instead. ```rust fn description(&self) -> &str ``` -------------------------------- ### Get File Name of DirEntry Source: https://docs.rs/globwalk/0.9.1/globwalk/type.DirEntry.html Retrieves the file name of the DirEntry. If the entry has no file name (e.g., the root path), the full path is returned. ```rust pub fn file_name(&self) -> &OsStr ``` -------------------------------- ### Get Full Path of DirEntry Source: https://docs.rs/globwalk/0.9.1/globwalk/type.DirEntry.html Retrieves the full path represented by the DirEntry. This method always returns the path as reported by the underlying directory entry, even when symbolic links are followed. ```rust pub fn path(&self) -> &Path ``` -------------------------------- ### Get Error Depth Source: https://docs.rs/globwalk/0.9.1/globwalk/type.WalkError.html Returns the depth at which the error occurred relative to the starting path of the walk. The root is at depth 0. ```rust pub fn depth(&self) -> usize ``` -------------------------------- ### Helper function to create files for testing Source: https://docs.rs/globwalk/0.9.1/src/globwalk/lib.rs.html Creates files with the given names in the specified directory. Used for setting up test environments. ```rust fn touch(dir: &TempDir, names: &[&str]) { for name in names { let name = normalize_path_sep(name); File::create(dir.path().join(name)).expect("Failed to create a test file"); } } ``` -------------------------------- ### type_id Source: https://docs.rs/globwalk/0.9.1/globwalk/struct.FileType.html Gets the `TypeId` of the `FileType` instance. ```APIDOC ## fn type_id(&self) -> TypeId ### Description Gets the `TypeId` of `self`. ### Method `type_id` ``` -------------------------------- ### Create All Flags Source: https://docs.rs/globwalk/0.9.1/globwalk/struct.FileType.html Creates a FileType with all known bits set. ```APIDOC ## all ### Description Get a flags value with all known bits set. ### Method `all() -> Self` ``` -------------------------------- ### Any Trait Implementation Source: https://docs.rs/globwalk/0.9.1/globwalk/struct.GlobWalkerBuilder.html Provides the `type_id` method to get the `TypeId` of an object. ```APIDOC ## fn type_id(&self) -> TypeId ### Description Gets the `TypeId` of `self`. ### Method `type_id` ### Parameters None ### Returns - `TypeId`: The unique identifier for the type of `self`. ``` -------------------------------- ### Match Directories Source: https://docs.rs/globwalk/0.9.1/src/globwalk/lib.rs.html Illustrates how to use a glob pattern to specifically match directories. This is useful for targeting directory structures within a file system traversal. ```rust fn test_match_dir() { let dir = TempDir::new().expect("Failed to create temporary folder"); let dir_path = dir.path(); create_dir_all(dir_path.join("mod")).expect(""); touch( &dir, &[ "a.png", "b.png", "c.png", "mod[/]a.png", "mod[/]b.png", "mod[/]c.png", ][..], ); let expected: Vec<_> = ["mod"].iter().map(normalize_path_sep).collect(); let glob = GlobWalkerBuilder::new(dir_path, "mod").build().unwrap(); equate_to_expected(glob, expected, dir_path); } ``` -------------------------------- ### Globwalk with Single Star Pattern and Sorting Source: https://docs.rs/globwalk/0.9.1/src/globwalk/lib.rs.html Demonstrates using a single star (*) for matching files in the current directory and applying a custom sort order. Useful for predictable traversal order. ```rust let glob = GlobWalkerBuilder::new(dir_path, "*") .sort_by(|a, b| a.path().cmp(b.path())) .build() .unwrap(); let expected = ["Pictures", "a.png", "b.png", "c.png"] .iter() .map(ToString::to_string) .collect(); equate_to_expected(glob, expected, dir_path); ``` -------------------------------- ### Get Bits Value Source: https://docs.rs/globwalk/0.9.1/globwalk/struct.FileType.html Retrieves the underlying unsigned integer representation of the flags. ```APIDOC ## bits ### Description Get the underlying bits value. ### Method `bits(&self) -> u32` ``` -------------------------------- ### Get Underlying Bits Type Source: https://docs.rs/globwalk/0.9.1/globwalk/struct.FileType.html Returns the underlying bits type used for storing the flags. ```APIDOC ## Bits ### Description The underlying bits type. ### Type Alias `Bits = u32` ``` -------------------------------- ### FileType Initialization Source: https://docs.rs/globwalk/0.9.1/globwalk/struct.FileType.html Methods for creating FileType instances, including empty, all known bits set, and from bit values. ```APIDOC ## FileType Initialization ### Description Methods for creating `FileType` instances, including empty, all known bits set, and from bit values. ### Methods - `empty()`: Returns a `FileType` with all bits unset. - `all()`: Returns a `FileType` with all known bits set. - `from_bits(bits: u32)`: Converts from a `u32` bit value. Returns `None` if unknown bits are set. - `from_bits_truncate(bits: u32)`: Converts from a `u32` bit value, unsetting any unknown bits. - `from_bits_retain(bits: u32)`: Converts from a `u32` bit value exactly. - `from_name(name: &str)`: Gets a `FileType` with the bits of a flag with the given name set. Returns `None` if the name is empty or doesn't correspond to a named flag. ``` -------------------------------- ### Error Trait: Cause Method Source: https://docs.rs/globwalk/0.9.1/globwalk/type.WalkError.html A deprecated method to get the underlying cause of the error. It is replaced by `Error::source` which supports downcasting. ```rust fn cause(&self) -> Option<&dyn Error> ``` -------------------------------- ### from Source: https://docs.rs/globwalk/0.9.1/globwalk/struct.FileType.html Creates a `FileType` from a given value. ```APIDOC ## fn from(t: T) -> T ### Description Returns the argument unchanged. ### Method `from` ``` -------------------------------- ### Get Loop Ancestor Path from WalkError Source: https://docs.rs/globwalk/0.9.1/globwalk/type.WalkError.html Returns the path at which a cycle was detected during directory traversal. Returns None if no cycle was found. ```rust pub fn loop_ancestor(&self) -> Option<&Path> ``` -------------------------------- ### Globwalk with Directory Blacklisting Source: https://docs.rs/globwalk/0.9.1/src/globwalk/lib.rs.html Illustrates how to exclude entire directories from the glob search using a blacklist pattern. Useful for ignoring specific subdirectories. ```rust let patterns = ["*.{png,jpg,gif}", "!Pictures"]; let glob = GlobWalkerBuilder::from_patterns(dir_path, &patterns) .build() .unwrap(); equate_to_expected(glob, expected, dir_path); ``` -------------------------------- ### Get Associated Path from WalkError Source: https://docs.rs/globwalk/0.9.1/globwalk/type.WalkError.html Retrieves the path associated with a WalkError, if available. Useful for identifying which file or directory caused the error. ```rust pub fn path(&self) -> Option<&Path> ``` -------------------------------- ### Create GlobWalker from Multiple Patterns Source: https://docs.rs/globwalk/0.9.1/src/globwalk/lib.rs.html Shows how to initialize a GlobWalker using an array of glob patterns. This allows for more complex and flexible file searching criteria. ```rust fn test_from_patterns() { let dir = TempDir::new().expect("Failed to create temporary folder"); let dir_path = dir.path(); create_dir_all(dir_path.join("src/some_mod")).expect(""); create_dir_all(dir_path.join("tests")).expect(""); create_dir_all(dir_path.join("contrib")).expect(""); touch( &dir, &[ "a.rs", "b.rs", "avocado.rs", "lib.c", "src[/]hello.rs", "src[/]world.rs", "src[/]some_mod[/]unexpected.rs", "src[/]cruel.txt", "contrib[/]README.md", "contrib[/]README.rst", "contrib[/]lib.rs", ][..], ); let expected: Vec<_> = [ "src[/]some_mod[/]unexpected.rs", "src[/]world.rs", "src[/]hello.rs", "lib.c", "contrib[/]lib.rs", "contrib[/]README.md", "contrib[/]README.rst", ] .iter() .map(normalize_path_sep) .collect(); let patterns = ["src/**/*.rs", "*.c", "**/lib.rs", "**/*.{md,rst}"]; let glob = GlobWalkerBuilder::from_patterns(dir_path, &patterns) .build() .unwrap(); equate_to_expected(glob, expected, dir_path); } ``` -------------------------------- ### Globwalk with Multiple Patterns and Exclusions Source: https://docs.rs/globwalk/0.9.1/src/globwalk/lib.rs.html Demonstrates building a GlobWalker with multiple patterns, including recursive matching and exclusions. Use when complex file filtering is required. ```rust let patterns = [ "src/**/*.rs", "*.c", "**/lib.rs", "**/*.{md,rst}", "!world.rs", ]; let glob = GlobWalkerBuilder::from_patterns(dir_path, &patterns) .build() .unwrap(); equate_to_expected(glob, expected, dir_path); ``` -------------------------------- ### Get Inode Number from DirEntry Source: https://docs.rs/globwalk/0.9.1/globwalk/type.DirEntry.html Retrieves the underlying `d_ino` field from the contained `dirent` structure, providing the inode number. This is part of the `DirEntryExt` trait implementation. ```rust fn ino(&self) -> u64 ``` -------------------------------- ### take Source: https://docs.rs/globwalk/0.9.1/globwalk/struct.GlobWalker.html Creates an iterator that yields the first `n` elements, or fewer if the underlying iterator ends sooner. ```APIDOC ## take ### Description Creates an iterator that yields the first `n` elements, or fewer if the underlying iterator ends sooner. ### Method Signature `fn take(self, n: usize) -> Take` ### Type Parameters - `Self`: The type of the iterator, must implement `Sized`. ``` -------------------------------- ### Globwalk with Double Star Pattern Source: https://docs.rs/globwalk/0.9.1/src/globwalk/lib.rs.html Shows how to use the double star (**) pattern for recursive directory matching in glob patterns. This is effective for searching in any subdirectory. ```rust let mut cwd = dir_path.clone(); cwd.push("**"); cwd.push("*.{png,jpg,gif}"); let glob = glob(cwd.to_str().unwrap().to_owned()).unwrap(); equate_to_expected(glob, expected, &dir_path); ``` -------------------------------- ### Consume and Get Original IO Error Source: https://docs.rs/globwalk/0.9.1/globwalk/type.WalkError.html Consumes the WalkError to return the original `io::Error` if one exists. This is useful for taking ownership of the underlying IO error. ```rust pub fn into_io_error(self) -> Option ``` -------------------------------- ### partition Source: https://docs.rs/globwalk/0.9.1/globwalk/struct.GlobWalker.html Consumes an iterator, creating two collections from it. ```APIDOC ## partition ### Description Consumes an iterator, creating two collections from it. ### Method Signature `fn partition(self, f: F) -> (B, B)` ### Type Parameters - `Self`: The type of the iterator, must implement `Sized`. - `B`: The type of the collections, must implement `Default + Extend`. - `F`: The closure type, which takes a reference to an item and returns a boolean. ``` -------------------------------- ### DirEntry Methods Source: https://docs.rs/globwalk/0.9.1/globwalk/type.DirEntry.html Provides access to various properties and information about a directory entry. ```APIDOC ## DirEntry A directory entry. This is the type of value that is yielded from the iterators defined in this crate. ### Methods #### `path(&self) -> &Path` The full path that this entry represents. The full path is created by joining the parents of this entry up to the root initially given to `WalkDir::new` with the file name of this entry. Note that this _always_ returns the path reported by the underlying directory entry, even when symbolic links are followed. To get the target path, use `path_is_symlink` to (cheaply) check if this entry corresponds to a symbolic link, and `std::fs::read_link` to resolve the target. #### `into_path(self) -> PathBuf` Analogous to `path`, but moves ownership of the path. #### `path_is_symlink(&self) -> bool` Returns `true` if and only if this entry was created from a symbolic link. This is unaffected by the `follow_links` setting. When `true`, the value returned by the `path` method is a symbolic link name. To get the full target path, you must call `std::fs::read_link(entry.path())`. #### `metadata(&self) -> Result` Return the metadata for the file that this entry points to. This will follow symbolic links if and only if the `WalkDir` value has `follow_links` enabled. Platform behavior: This always calls `std::fs::symlink_metadata`. If this entry is a symbolic link and `follow_links` is enabled, then `std::fs::metadata` is called instead. Errors: Similar to `std::fs::metadata`, returns errors for path values that the program does not have permissions to access or if the path does not exist. #### `file_type(&self) -> FileType` Return the file type for the file that this entry points to. If this is a symbolic link and `follow_links` is `true`, then this returns the type of the target. This never makes any system calls. #### `file_name(&self) -> &OsStr` Return the file name of this entry. If this entry has no file name (e.g., `/`), then the full path is returned. #### `depth(&self) -> usize` Returns the depth at which this entry was created relative to the root. The smallest depth is `0` and always corresponds to the path given to the `new` function on `WalkDir`. Its direct descendents have depth `1`, and their descendents have depth `2`, and so on. #### `ino(&self) -> u64` Returns the underlying `d_ino` field in the contained `dirent` structure. ``` -------------------------------- ### into Source: https://docs.rs/globwalk/0.9.1/globwalk/struct.FileType.html Converts the `FileType` instance into another type `U` for which `U` implements `From`. ```APIDOC ## fn into(self) -> U ### Description Calls `U::from(self)`. That is, this conversion is whatever the implementation of `From for U` chooses to do. ### Method `into` ``` -------------------------------- ### Create from Flag Name Source: https://docs.rs/globwalk/0.9.1/globwalk/struct.FileType.html Retrieves a FileType with the bits of a flag with the given name set. ```APIDOC ## from_name ### Description Get a flags value with the bits of a flag with the given name set. ### Method `from_name(name: &str) -> Option` ``` -------------------------------- ### Create GlobWalker with a Single Pattern Source: https://docs.rs/globwalk/0.9.1/src/globwalk/lib.rs.html Demonstrates creating a GlobWalker instance with a single glob pattern. This is useful for simple file searching based on a specific pattern. ```rust fn test_new() { let dir = TempDir::new().expect("Failed to create temporary folder"); let dir_path = dir.path(); touch(&dir, &["a.rs", "a.jpg", "a.png", "b.docx"][..]); let expected = ["a.jpg", "a.png"].iter().map(ToString::to_string).collect(); let g = GlobWalkerBuilder::new(dir_path, "*.{png,jpg,gif}") .build() .unwrap(); equate_to_expected(g, expected, dir_path); } ``` -------------------------------- ### borrow Source: https://docs.rs/globwalk/0.9.1/globwalk/struct.FileType.html Immutably borrows the `FileType` instance. ```APIDOC ## fn borrow(&self) -> &T ### Description Immutably borrows from an owned value. ### Method `borrow` ``` -------------------------------- ### by_ref Source: https://docs.rs/globwalk/0.9.1/globwalk/struct.GlobWalker.html Creates a “by reference” adapter for this instance of `Iterator`. ```APIDOC ## by_ref ### Description Creates a “by reference” adapter for this instance of `Iterator`. ### Method Signature `fn by_ref(&mut self) -> &mut Self` ### Type Parameters - `Self`: The type of the iterator, must implement `Sized`. ``` -------------------------------- ### Blacklisting Files Source: https://docs.rs/globwalk/0.9.1/src/globwalk/lib.rs.html Demonstrates how to exclude specific files or patterns from the glob walk results using a blacklist. This is useful for ignoring certain files during traversal. ```rust fn test_blacklist() { let dir = TempDir::new().expect("Failed to create temporary folder"); let dir_path = dir.path(); create_dir_all(dir_path.join("src/some_mod")).expect(""); create_dir_all(dir_path.join("tests")).expect(""); create_dir_all(dir_path.join("contrib")).expect(""); touch( &dir, &[ "a.rs", "b.rs", "avocado.rs", "lib.c", "src[/]hello.rs", "src[/]world.rs", ``` -------------------------------- ### Create Empty Flags Source: https://docs.rs/globwalk/0.9.1/globwalk/struct.FileType.html Creates a FileType with all bits unset. ```APIDOC ## empty ### Description Get a flags value with all bits unset. ### Method `empty() -> Self` ``` -------------------------------- ### product Source: https://docs.rs/globwalk/0.9.1/globwalk/struct.GlobWalker.html Iterates over the entire iterator, multiplying all the elements. ```APIDOC ## fn product

(self) -> P where Self: Sized, P: Product, Iterates over the entire iterator, multiplying all the elements Read more ``` -------------------------------- ### Find and Remove Image Files Source: https://docs.rs/globwalk/0.9.1/index.html Finds all files matching the '*.{png,jpg,gif}' pattern in the current directory and attempts to remove them. Requires the globwalk crate and std::fs module. ```rust extern crate globwalk; use std::fs; for img in globwalk::glob("*.{png,jpg,gif}")? { if let Ok(img) = img { fs::remove_file(img.path())?; } } ``` -------------------------------- ### Create from Exact Bits Source: https://docs.rs/globwalk/0.9.1/globwalk/struct.FileType.html Creates a FileType from a specific bits value, ensuring an exact match. ```APIDOC ## from_bits_retain ### Description Convert from a bits value exactly. ### Method `from_bits_retain(bits: u32) -> FileType` ``` -------------------------------- ### try_from Source: https://docs.rs/globwalk/0.9.1/globwalk/struct.FileType.html Attempts to convert a value of type `U` into `FileType`. Returns a `Result` indicating success or failure. ```APIDOC ## fn try_from(value: U) -> Result>::Error> ### Description Performs the conversion. ### Method `try_from` ``` -------------------------------- ### Advanced Globbing with GlobWalkerBuilder Source: https://docs.rs/globwalk/0.9.1/index.html Demonstrates advanced globbing using GlobWalkerBuilder to specify multiple patterns, set max depth, and control symlink following. Useful for complex directory traversal scenarios. ```rust extern crate globwalk; use std::fs; let walker = globwalk::GlobWalkerBuilder::from_patterns( BASE_DIR, &["*.{png,jpg,gif}", "!Pictures/*"], ) .max_depth(4) .follow_links(true) .build()? .into_iter() .filter_map(Result::ok); for img in walker { fs::remove_file(img.path())?; } ``` -------------------------------- ### Create from Bits Source: https://docs.rs/globwalk/0.9.1/globwalk/struct.FileType.html Safely converts from a bits value, returning None if unknown bits are present. ```APIDOC ## from_bits ### Description Convert from a bits value. ### Method `from_bits(bits: Self::Bits) -> Option` ``` -------------------------------- ### Check if All Set Source: https://docs.rs/globwalk/0.9.1/globwalk/struct.FileType.html Determines if all known bits in the FileType are set. ```APIDOC ## is_all ### Description Whether all known bits in this flags value are set. ### Method `is_all(&self) -> bool` ``` -------------------------------- ### borrow_mut Source: https://docs.rs/globwalk/0.9.1/globwalk/struct.FileType.html Mutably borrows the `FileType` instance. ```APIDOC ## fn borrow_mut(&mut self) -> &mut T ### Description Mutably borrows from an owned value. ### Method `borrow_mut` ``` -------------------------------- ### GlobWalkerBuilder::follow_links Source: https://docs.rs/globwalk/0.9.1/src/globwalk/lib.rs.html Configures whether to follow symbolic links. When enabled, symbolic links are treated as regular files or directories. ```APIDOC ## GlobWalkerBuilder::follow_links ### Description 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. ### Signature ```rust pub fn follow_links(mut self, yes: bool) -> Self ``` ### Parameters * `yes`: A boolean indicating whether to follow symbolic links. ``` -------------------------------- ### inspect Source: https://docs.rs/globwalk/0.9.1/globwalk/struct.GlobWalker.html Does something with each element of an iterator, passing the value on. ```APIDOC ## inspect ### Description Does something with each element of an iterator, passing the value on. ### Method Signature `fn inspect(self, f: F) -> Inspect` ### Type Parameters - `Self`: The type of the iterator, must implement `Sized`. - `F`: The closure type, which takes a reference to the item. ``` -------------------------------- ### Create from Iterator Source: https://docs.rs/globwalk/0.9.1/globwalk/struct.FileType.html Creates a FileType by performing a bitwise OR on all elements from an iterator. ```APIDOC ## from_iter> ### Description The bitwise or (`|`) of the bits in each flags value. ### Method `from_iter>(iterator: T) -> Self` ``` -------------------------------- ### map_windows Source: https://docs.rs/globwalk/0.9.1/globwalk/struct.GlobWalker.html Calls the given function `f` for each contiguous window of size `N` over `self` and returns an iterator over the outputs of `f`. Like `slice::windows()`, the windows during mapping overlap as well. ```APIDOC ## map_windows ### Description Calls the given function `f` for each contiguous window of size `N` over `self` and returns an iterator over the outputs of `f`. Like `slice::windows()`, the windows during mapping overlap as well. ### Method Signature `fn map_windows(self, f: F) -> MapWindows` ### Type Parameters - `Self`: The type of the iterator, must implement `Sized`. - `F`: The closure type, which takes a slice of `N` items and returns a value `R`. - `R`: The type of the elements produced by the new iterator. - `N`: The size of the sliding window. ``` -------------------------------- ### try_into Source: https://docs.rs/globwalk/0.9.1/globwalk/struct.FileType.html Attempts to convert the `FileType` instance into another type `U` for which `U` implements `TryFrom`. Returns a `Result` indicating success or failure. ```APIDOC ## fn try_into(self) -> Result>::Error> ### Description Performs the conversion. ### Method `try_into` ``` -------------------------------- ### Error Trait: Provide Method (Experimental) Source: https://docs.rs/globwalk/0.9.1/globwalk/type.WalkError.html An experimental, nightly-only API for providing type-based access to error context, intended for error reporting. ```rust fn provide<'a>(&'a self, request: &mut Request<'a>) ``` -------------------------------- ### From Trait Implementation Source: https://docs.rs/globwalk/0.9.1/globwalk/struct.GlobWalkerBuilder.html Provides the `from` method for creating a value from another. ```APIDOC ## fn from(t: T) -> T ### Description Returns the argument unchanged. ### Method `from` ### Parameters - `t` (T): The value to convert from. ### Returns - `T`: The converted value. ``` -------------------------------- ### Format as Octal Source: https://docs.rs/globwalk/0.9.1/globwalk/struct.FileType.html Formats the FileType value as an octal string. ```APIDOC ## fmt (Octal) ### Description Formats the value using the given formatter. ### Method `fmt(&self, f: &mut Formatter<'_>) -> Result` ``` -------------------------------- ### GlobWalkerBuilder::new Source: https://docs.rs/globwalk/0.9.1/src/globwalk/lib.rs.html Constructs a new GlobWalkerBuilder with a single glob pattern. It recursively searches the base directory for paths matching the pattern. ```APIDOC ## GlobWalkerBuilder::new ### Description Construct a new `GlobWalker` with a glob pattern. When iterated, the `base` directory will be recursively searched for paths matching `pattern`. ### Signature ```rust pub fn new(base: P, pattern: S) -> Self where P: AsRef, S: AsRef, ``` ### Parameters * `base`: The starting directory for the search. * `pattern`: The glob pattern to match files against. ``` -------------------------------- ### GlobWalkerBuilder::contents_first Source: https://docs.rs/globwalk/0.9.1/globwalk/struct.GlobWalkerBuilder.html Configures the order in which directories and their contents are yielded. When enabled, a directory's contents are yielded before the directory itself. ```APIDOC ## GlobWalkerBuilder::contents_first ### Description Yield a directory’s contents before the directory itself. By default, this is disabled. When `yes` is `false` (as is the default), the directory is yielded before its contents are read. This is useful when, e.g. you want to skip processing of some directories. When `yes` is `true`, the iterator yields the contents of a directory before yielding the directory itself. This is useful when, e.g. you want to recursively delete a directory. ### Signature ```rust pub fn contents_first(self, yes: bool) -> Self ``` ``` -------------------------------- ### GlobWalker Builder Methods Source: https://docs.rs/globwalk/0.9.1/src/globwalk/lib.rs.html These methods are part of the builder pattern used to configure a GlobWalker instance before building it. They allow for sorting, controlling directory traversal order, and setting case sensitivity. ```APIDOC ## sort_by(mut self, cmp: F) -> Self ### Description If a compare function is set, the resulting iterator will return all paths in sorted order. The compare function will be called to compare entries from the same directory. ### Parameters * `cmp` (F): A mutable closure that takes two `DirEntry` references and returns an `Ordering`. It must be `Send + Sync + 'static`. ``` ```APIDOC ## contents_first(mut self, yes: bool) -> Self ### Description Yield a directory's contents before the directory itself. By default, this is disabled. When `yes` is `false` (as is the default), the directory is yielded before its contents are read. This is useful when, e.g. you want to skip processing of some directories. When `yes` is `true`, the iterator yields the contents of a directory before yielding the directory itself. This is useful when, e.g. you want to recursively delete a directory. ### Parameters * `yes` (bool): If `true`, yields directory contents first. If `false`, yields the directory first. ``` ```APIDOC ## case_insensitive(mut self, yes: bool) -> Self ### Description Toggle whether the globs should be matched case insensitively or not. This is disabled by default. ### Parameters * `yes` (bool): If `true`, enables case-insensitive matching. If `false`, disables it. ``` ```APIDOC ## file_type(mut self, file_type: FileType) -> Self ### Description Toggle filtering by file type. `FileType` can be an OR of several types. Note that not all file-types can be whitelisted by this filter (e.g. char-devices, fifos, etc.). ### Parameters * `file_type` (FileType): The file type(s) to filter by. ``` ```APIDOC ## build(self) -> Result ### Description Finalize and build a `GlobWalker` instance. This method consumes the builder and returns a `GlobWalker` iterator. ### Returns A `Result` containing a `GlobWalker` instance on success, or a `GlobError` on failure. ``` -------------------------------- ### Compare glob walker results with expected files Source: https://docs.rs/globwalk/0.9.1/src/globwalk/lib.rs.html Iterates through a GlobWalker and compares the matched files against a list of expected file names. Panics if an unexpected file is found or if an expected file is missing. ```rust fn equate_to_expected(g: GlobWalker, mut expected: Vec, dir_path: &Path) { for matched_file in g.into_iter().filter_map(Result::ok) { let path = matched_file .path() .strip_prefix(dir_path) .unwrap() .to_str() .unwrap(); let path = normalize_path_sep(path); let del_idx = if let Some(idx) = expected.iter().position(|n| &path == n) { idx } else { panic!("Iterated file is unexpected: {}", path); }; expected.remove(del_idx); } // Not equating `.len() == 0` so that the assertion output // will contain the extra files let empty: &[&str] = &[][..]; assert_eq!(expected, empty); } ``` -------------------------------- ### any Source: https://docs.rs/globwalk/0.9.1/globwalk/struct.GlobWalker.html Tests if any element of the iterator matches a predicate. ```APIDOC ## fn any(&mut self, f: F) -> bool where Self: Sized, F: FnMut(Self::Item) -> bool, Tests if any element of the iterator matches a predicate. Read more ``` -------------------------------- ### fold Source: https://docs.rs/globwalk/0.9.1/globwalk/struct.GlobWalker.html Folds every element into an accumulator by applying an operation, returning the final result. ```APIDOC ## fold ### Description Folds every element into an accumulator by applying an operation, returning the final result. ### Method Signature `fn fold(self, init: B, f: F) -> B` ### Type Parameters - `Self`: The type of the iterator, must implement `Sized`. - `B`: The type of the accumulator and the final result. - `F`: The closure type, which takes the accumulator and the next item, returning the updated accumulator. ``` -------------------------------- ### Create from Bits with Truncation Source: https://docs.rs/globwalk/0.9.1/globwalk/struct.FileType.html Converts from a bits value, unsetting any unknown bits. ```APIDOC ## from_bits_truncate ### Description Convert from a bits value, unsetting any unknown bits. ### Method `from_bits_truncate(bits: Self::Bits) -> Self` ``` -------------------------------- ### GlobWalkerBuilder::from_patterns Source: https://docs.rs/globwalk/0.9.1/globwalk/struct.GlobWalkerBuilder.html Constructs a new GlobWalker from a base directory and a list of glob patterns. The builder will recursively search the base directory for paths matching any of the provided patterns. ```APIDOC ## GlobWalkerBuilder::from_patterns ### Description Construct a new `GlobWalker` from a list of patterns. When iterated, the `base` directory will be recursively searched for paths matching `patterns`. ### Signature ```rust pub fn from_patterns(base: P, patterns: &[S]) -> Self where P: AsRef, S: AsRef, ``` ``` -------------------------------- ### Globwalk Filtering by Directory Type Source: https://docs.rs/globwalk/0.9.1/src/globwalk/lib.rs.html Shows how to configure GlobWalker to only traverse directories. Use when only directory entries are of interest. ```rust let glob = GlobWalkerBuilder::new(dir_path, "*") .sort_by(|a, b| a.path().cmp(b.path())) .file_type(FileType::DIR) .build() .unwrap(); let expected = ["Pictures"].iter().map(ToString::to_string).collect(); equate_to_expected(glob, expected, dir_path); ``` -------------------------------- ### copied Source: https://docs.rs/globwalk/0.9.1/globwalk/struct.GlobWalker.html Creates an iterator that copies all of its elements. ```APIDOC ## fn copied<'a, T>(self) -> Copied where T: Copy + 'a, Self: Sized + Iterator, Creates an iterator which copies all of its elements. Read more ``` -------------------------------- ### Construct a new GlobWalker with a glob pattern Source: https://docs.rs/globwalk/0.9.1/src/globwalk/lib.rs.html Creates a new GlobWalker instance. This function is a convenience wrapper around `glob_builder` and `build`. ```rust pub fn glob>(pattern: S) -> Result { glob_builder(pattern).build() } ``` -------------------------------- ### partial_cmp_by Source: https://docs.rs/globwalk/0.9.1/globwalk/struct.GlobWalker.html Lexicographically compares elements with another iterator using a provided comparison function. This is a nightly-only experimental API. ```APIDOC ## fn partial_cmp_by(self, other: I, partial_cmp: F) -> Option where Self: Sized, I: IntoIterator, F: FnMut(Self::Item, ::Item) -> Option, ### Description Lexicographically compares the elements of this `Iterator` with those of another with respect to the specified comparison function. ### Parameters - **other**: An iterator to compare against. - **partial_cmp**: A closure that takes two elements and returns an `Option`. ### Returns An `Option` representing the comparison result. ``` -------------------------------- ### GlobWalkerBuilder::new Source: https://docs.rs/globwalk/0.9.1/globwalk/struct.GlobWalkerBuilder.html Constructs a new GlobWalker with a base directory and a single glob pattern. The builder will recursively search the base directory for paths matching the pattern. ```APIDOC ## GlobWalkerBuilder::new ### Description Construct a new `GlobWalker` with a glob pattern. When iterated, the `base` directory will be recursively searched for paths matching `pattern`. ### Signature ```rust pub fn new(base: P, pattern: S) -> Self where P: AsRef, S: AsRef, ``` ``` -------------------------------- ### glob Function Source: https://docs.rs/globwalk/0.9.1/globwalk/all.html The `glob` function provides a convenient way to create a GlobWalker instance for iterating over files matching a given pattern. ```APIDOC ## glob ### Description Creates a `GlobWalker` from a glob pattern. ### Function Signature `pub fn glob(pattern: &str) -> Result` ### Parameters * **pattern** (`&str`) - Required - The glob pattern to match files against. ### Returns A `Result` containing a `GlobWalker` on success or a `GlobError` on failure. ``` -------------------------------- ### GlobWalkerBuilder::follow_links Source: https://docs.rs/globwalk/0.9.1/globwalk/struct.GlobWalkerBuilder.html Configures whether the iterator should follow symbolic links. When enabled, symbolic links are treated as regular files or directories. Broken links or loops will result in an error. ```APIDOC ## GlobWalkerBuilder::follow_links ### Description 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. ### Signature ```rust pub fn follow_links(self, yes: bool) -> Self ``` ``` -------------------------------- ### Check if Empty Source: https://docs.rs/globwalk/0.9.1/globwalk/struct.FileType.html Determines if all bits in the FileType are unset. ```APIDOC ## is_empty ### Description Whether all bits in this flags value are unset. ### Method `is_empty(&self) -> bool` ``` -------------------------------- ### Clone From DirEntry Source: https://docs.rs/globwalk/0.9.1/globwalk/type.DirEntry.html Performs copy-assignment from a source DirEntry to the current one. This implementation is part of the `Clone` trait. ```rust fn clone_from(&mut self, source: &Self) ``` -------------------------------- ### glob Source: https://docs.rs/globwalk/0.9.1/globwalk/fn.glob.html Constructs a new GlobWalker with a glob pattern. When iterated, the current directory will be recursively searched for paths matching pattern, unless the pattern specifies an absolute path. ```APIDOC ## glob ### Description Constructs a new `GlobWalker` with a glob pattern. When iterated, the current directory will be recursively searched for paths matching `pattern`, unless the pattern specifies an absolute path. ### Signature ```rust pub fn glob>(pattern: S) -> Result ``` ### Parameters #### Path Parameters - **pattern** (S: AsRef) - Required - The glob pattern to match files against. ### Returns - **Result** - A `Result` containing a `GlobWalker` if the pattern is valid, or a `GlobError` otherwise. ``` -------------------------------- ### Into Trait Implementation Source: https://docs.rs/globwalk/0.9.1/globwalk/struct.GlobWalkerBuilder.html Provides the `into` method for converting a value into another type. ```APIDOC ## fn into(self) -> U ### Description Calls `U::from(self)`. That is, this conversion is whatever the implementation of `From for U` chooses to do. ### Method `into` ### Parameters None ### Returns - `U`: The converted value. ``` -------------------------------- ### skip Source: https://docs.rs/globwalk/0.9.1/globwalk/struct.GlobWalker.html Creates an iterator that skips the first `n` elements. ```APIDOC ## skip ### Description Creates an iterator that skips the first `n` elements. ### Method Signature `fn skip(self, n: usize) -> Skip` ### Type Parameters - `Self`: The type of the iterator, must implement `Sized`. ``` -------------------------------- ### Error Handling Implementations Source: https://docs.rs/globwalk/0.9.1/globwalk/struct.GlobError.html Provides implementations for standard Rust error traits, allowing GlobError to be used within Rust's error handling mechanisms. ```APIDOC ## Trait Implementations ### impl Debug for GlobError #### fn fmt(&self, f: &mut Formatter<'_>) -> Result Formats the value using the given formatter. ### impl Display for GlobError #### fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error> Formats the value using the given formatter. ### impl Error for GlobError #### fn source(&self) -> Option<&(dyn Error + 'static)> Returns the lower-level source of this error, if any. #### fn description(&self) -> &str Deprecated since 1.42.0: use the Display impl or to_string(). #### fn cause(&self) -> Option<&dyn Error> Deprecated since 1.33.0: replaced by Error::source, which can support downcasting. #### fn provide<'a>(&'a self, request: &mut Request<'a>) Nightly-only experimental API. Provides type-based access to context intended for error reports. ### impl From for GlobError #### fn from(e: Error) -> Self Converts to this type from the input type. ### impl From for Error #### fn from(e: GlobError) -> Self Converts to this type from the input type. ``` -------------------------------- ### Union of Flags Source: https://docs.rs/globwalk/0.9.1/globwalk/struct.FileType.html Computes the bitwise OR of two FileType values. ```APIDOC ## union ### Description The bitwise or (`|`) of the bits in two flags values. ### Method `union(self, other: Self) -> Self` ``` -------------------------------- ### cloned Source: https://docs.rs/globwalk/0.9.1/globwalk/struct.GlobWalker.html Creates an iterator that clones all of its elements. ```APIDOC ## fn cloned<'a, T>(self) -> Cloned where T: Clone + 'a, Self: Sized + Iterator, Creates an iterator which `clone`s all of its elements. Read more ``` -------------------------------- ### Difference of Flags Source: https://docs.rs/globwalk/0.9.1/globwalk/struct.FileType.html Computes the difference between two FileType values (self & !other). ```APIDOC ## difference ### Description The intersection of a source flags value with the complement of a target flags value (`&!`). ### Method `difference(self, other: Self) -> Self` ``` -------------------------------- ### Check if DirEntry is a Symbolic Link Source: https://docs.rs/globwalk/0.9.1/globwalk/type.DirEntry.html Determines if the DirEntry was created from a symbolic link. This check is unaffected by the `follow_links` setting. If true, `path` returns the link name, and `std::fs::read_link` is needed for the target path. ```rust pub fn path_is_symlink(&self) -> bool ``` -------------------------------- ### Collect Glob Results into Expected Vector Source: https://docs.rs/globwalk/0.9.1/src/globwalk/lib.rs.html Collects glob results into a vector of strings for comparison with expected values. Ensure the `equate_to_expected` function is available for testing. ```rust let expected = [ "a.png", "b.png", "c.png", ] .iter() .map(ToString::to_string) .collect(); equate_to_expected(glob, expected, dir_path); ``` -------------------------------- ### Create Iterator from Value Source: https://docs.rs/globwalk/0.9.1/globwalk/struct.FileType.html Creates an iterator from a FileType value. ```APIDOC ## into_iter ### Description Creates an iterator from a value. ### Method `into_iter(self) -> Self::IntoIter` ``` -------------------------------- ### scan Source: https://docs.rs/globwalk/0.9.1/globwalk/struct.GlobWalker.html An iterator adapter which, like `fold`, holds internal state, but unlike `fold`, produces a new iterator. ```APIDOC ## scan ### Description An iterator adapter which, like `fold`, holds internal state, but unlike `fold`, produces a new iterator. ### Method Signature `fn scan(self, initial_state: St, f: F) -> Scan` ### Type Parameters - `Self`: The type of the iterator, must implement `Sized`. - `St`: The type of the internal state. - `B`: The type of the elements produced by the new iterator. - `F`: The closure type, which takes a mutable reference to the state and the next item, returning an `Option`. ``` -------------------------------- ### Toggle Flags Source: https://docs.rs/globwalk/0.9.1/globwalk/struct.FileType.html Toggles bits in the FileType by performing a bitwise XOR with another FileType. ```APIDOC ## toggle ### Description The bitwise exclusive-or (`^`) of the bits in two flags values. ### Method `toggle(&mut self, other: Self)` ``` -------------------------------- ### Normalize path separators for cross-platform compatibility Source: https://docs.rs/globwalk/0.9.1/src/globwalk/lib.rs.html Replaces path separators in a string to match the current platform's convention. This is useful for consistent path handling in tests. ```rust fn normalize_path_sep>(s: S) -> String { s.as_ref() .replace("[ /]", if cfg!(windows) { \"\\\" } else { "/" }) } ```