pub enum CompiledPattern {
MatchAll,
RootFilesOnly,
ExtensionSuffix(String),
SingleSegmentGlob(String),
MultiSegmentGlob(String),
AnchoredDirectory(String),
UnanchoredDirectory(String),
Exact(String),
}Expand description
A CODEOWNERS pattern, pre-processed for repeated fast matching.
Use CompiledPattern::new to compile, then CompiledPattern::matches
to match paths. Construction is O(pattern length); matching is close to
O(path length) for all variants except the glob ones.
Variants§
MatchAll
Matches everything (unanchored * or **).
RootFilesOnly
Anchored /* — matches only root-level files (no slashes in path).
ExtensionSuffix(String)
Extension suffix like .rs (from *.rs) — simple ends_with check.
Stored as the literal suffix including the leading dot. Matcher also
verifies there is a / immediately before the suffix to avoid false
positives like notrs matching .rs.
SingleSegmentGlob(String)
Single-segment glob like *.rs that fell out of the extension
fast-path — matched via fast_glob with a prepended **/ so it
triggers in any directory.
MultiSegmentGlob(String)
Multi-segment glob like src/**/*.rs — matched directly via fast_glob.
AnchoredDirectory(String)
Anchored directory pattern like /src/ — matches a prefix at the root only.
UnanchoredDirectory(String)
Unanchored directory pattern like docs/ — matches anywhere in the tree.
Exact(String)
An exact path, always anchored (no wildcards, no trailing slash).
Implementations§
Source§impl CompiledPattern
impl CompiledPattern
Sourcepub fn new(pattern: &str) -> Self
pub fn new(pattern: &str) -> Self
Compile a CODEOWNERS pattern string into a specialized matcher.
The leading / (anchor) is inspected to distinguish anchored from
unanchored directory patterns; a trailing / selects directory
matching over exact matching.
Sourcepub fn matches(&self, path: &str) -> bool
pub fn matches(&self, path: &str) -> bool
Test whether path matches this pattern.
Empty paths never match. Pattern semantics follow GitHub’s
CODEOWNERS rules (last match wins is handled by the caller —
see check_file_ownership_parsed).