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 split_static_dir(&self) -> (PathBuf, GlobPath)
pub fn split_static_dir(&self) -> (PathBuf, GlobPath)
Split the pattern into its deepest static directory prefix and the remaining pattern to match beneath it.
Used to start a walk from the literal leading directories instead of
the filesystem root: walking from / is O(filesystem) and skips
hidden intermediate directories, so /tmp/.tmpXXXX/*.txt would match
nothing. At least one segment is always kept in the remaining pattern,
so an all-literal pattern (/a/b/c.txt) walks /a/b and matches
c.txt rather than trying to descend into the file itself. The
returned pattern is unanchored (the anchor is consumed by the caller’s
walk root).
§Examples
use kaish_glob::GlobPath;
use std::path::{Path, PathBuf};
let (dir, rest) = GlobPath::new("/a/b/*.txt").unwrap().split_static_dir();
assert_eq!(dir, PathBuf::from("a/b"));
assert!(rest.matches(Path::new("c.txt")));
// All-literal: the final component stays in the match pattern.
let (dir, rest) = GlobPath::new("/a/b/c.txt").unwrap().split_static_dir();
assert_eq!(dir, PathBuf::from("a/b"));
assert!(rest.matches(Path::new("c.txt")));
// No static prefix (leading wildcard / globstar): empty dir, full pattern.
let (dir, _rest) = GlobPath::new("**/*.rs").unwrap().split_static_dir();
assert_eq!(dir, PathBuf::new());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).
Sourcepub fn matches_walk(&self, path: &Path, dotglob: bool) -> bool
pub fn matches_walk(&self, path: &Path, dotglob: bool) -> bool
Match a path under file-walk semantics, honouring the leading-dot rule.
When dotglob is false (the default) a leading . in a path component
is matched only by a segment that explicitly begins with a literal .:
bare wildcards (*, ?, […]) and globstar (**) skip dot entries, so
* hides dotfiles while .*, .github, and **/.env reach them.
dotglob == true disables the rule (bash shopt -s dotglob).
This differs from matches, which is dotfile-agnostic
and used for include/exclude filtering of already-walked paths.
Sourcepub fn could_descend(&self, dir: &Path, dotglob: bool) -> bool
pub fn could_descend(&self, dir: &Path, dotglob: bool) -> bool
Whether the walker should descend into the directory at relative path
dir — i.e. whether some entry beneath it could still match.
Honours the same leading-dot rule as matches_walk:
** does not descend into hidden directories without dotglob, while an
explicitly named dot directory (.github, or a .foo segment reached
through a zero-width **) is entered.
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 UnsafeUnpin 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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
Source§fn with_current_context(self) -> WithContext<Self> ⓘ
fn with_current_context(self) -> WithContext<Self> ⓘ
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
impl<T> OrderedSeq<'_, T> for Twhere
T: Clone,
Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<'p, T> Seq<'p, T> for Twhere
T: Clone,
impl<'p, T> Seq<'p, T> for Twhere
T: Clone,
Source§impl<T, S> SpanWrap<S> for Twhere
S: WrappingSpan<T>,
impl<T, S> SpanWrap<S> for Twhere
S: WrappingSpan<T>,
Source§fn with_span(self, span: S) -> <S as WrappingSpan<Self>>::Spanned
fn with_span(self, span: S) -> <S as WrappingSpan<Self>>::Spanned
WrappingSpan::make_wrapped to wrap an AST node in a span.