pub struct GlobPath { /* private fields */ }Expand description
A path-aware glob pattern with globstar support.
§Examples
use kaish_glob::GlobPath;
use std::path::Path;
let pattern = GlobPath::new("**/*.rs").unwrap();
assert!(pattern.matches(Path::new("main.rs")));
assert!(pattern.matches(Path::new("src/main.rs")));
assert!(pattern.matches(Path::new("src/lib/utils.rs")));
assert!(!pattern.matches(Path::new("README.md")));Implementations§
Source§impl GlobPath
impl GlobPath
Sourcepub fn new(pattern: &str) -> Result<GlobPath, PatternError>
pub fn new(pattern: &str) -> Result<GlobPath, PatternError>
Parse a glob pattern into a GlobPath.
Patterns starting with / are anchored to the root.
** matches zero or more directory components.
Sourcepub fn static_prefix(&self) -> Option<PathBuf>
pub fn static_prefix(&self) -> Option<PathBuf>
Get the static prefix of the pattern (directories before any wildcard).
This is useful for optimization: we can start the walk from this prefix instead of the root.
§Examples
use kaish_glob::GlobPath;
use std::path::PathBuf;
let pattern = GlobPath::new("src/lib/**/*.rs").unwrap();
assert_eq!(pattern.static_prefix(), Some(PathBuf::from("src/lib")));
let pattern = GlobPath::new("**/*.rs").unwrap();
assert_eq!(pattern.static_prefix(), None);Sourcepub fn is_dir_only(&self) -> bool
pub fn is_dir_only(&self) -> bool
Check if the pattern only matches directories.
Sourcepub fn is_anchored(&self) -> bool
pub fn is_anchored(&self) -> bool
Check if the pattern is anchored (starts with /).
Sourcepub fn has_globstar(&self) -> bool
pub fn has_globstar(&self) -> bool
Check if the pattern contains a globstar (**).
Patterns with globstar require recursive directory traversal. Patterns without globstar only match at a fixed depth.
Sourcepub fn fixed_depth(&self) -> Option<usize>
pub fn fixed_depth(&self) -> Option<usize>
Get the depth of the pattern (number of path components).
Returns None if the pattern contains globstar (variable depth).
Trait Implementations§
Auto Trait Implementations§
impl Freeze for GlobPath
impl RefUnwindSafe for GlobPath
impl Send for GlobPath
impl Sync for GlobPath
impl Unpin for GlobPath
impl UnwindSafe for GlobPath
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