pub enum PathPattern {
Literal(HazPath),
Glob(GlobPattern),
}Expand description
A validated path pattern: either a literal HazPath or a
GlobPattern.
Construction is via PathPattern::parse. The
fmt::Display implementation produces the canonical text,
which round-trips through PathPattern::parse.
§Examples
use haz_domain::path::PathPattern;
let p = PathPattern::parse("src/lib.rs").unwrap();
assert!(matches!(p, PathPattern::Literal(_)));
let g = PathPattern::parse("src/**/*.rs").unwrap();
assert!(matches!(g, PathPattern::Glob(_)));Variants§
Implementations§
Source§impl PathPattern
impl PathPattern
Sourcepub fn parse(s: &str) -> Result<Self, PathPatternError>
pub fn parse(s: &str) -> Result<Self, PathPatternError>
Parse s as a PathPattern.
Classification rule: if s contains any of *, ?, [,
{, or \, the input is a glob; otherwise it is parsed as
a literal HazPath. The escape character \ is glob
syntax (PATH-015), so its mere presence is enough to
classify the input as a glob.
§Errors
Returns a PathPatternError when s violates path or
glob rules:
PathPatternError::EmptyInputifsis the empty string.PathPatternError::OnlySlashifsis"/".PathPatternError::EmptySegmentifscontains//.PathPatternError::TrailingSlashifsends with/.PathPatternError::LiteralPathif the literal sub-form (HazPath) rejects the input.PathPatternError::InvalidGlobSegmentif a glob segment violatesPATH-002orPATH-011.PathPatternError::InvalidGlobifglobsetrejects the structural form (for example, an unclosed[or nested{}).
§Examples
use haz_domain::path::PathPattern;
assert!(PathPattern::parse("src/lib.rs").is_ok());
assert!(PathPattern::parse("/lib_core/src/main.rs").is_ok());
assert!(PathPattern::parse("src/**/*.rs").is_ok());
assert!(PathPattern::parse("/lib_core/src/**/*.rs").is_ok());
assert!(PathPattern::parse("with\\*literal.txt").is_ok());
assert!(PathPattern::parse("").is_err());
assert!(PathPattern::parse("a**b/foo.rs").is_err());Sourcepub fn is_literal(&self) -> bool
pub fn is_literal(&self) -> bool
true if this pattern is a literal path (no wildcards).
Sourcepub fn anchor(&self) -> PathAnchor
pub fn anchor(&self) -> PathAnchor
The anchor (workspace-absolute or project-relative).
Trait Implementations§
Source§impl Clone for PathPattern
impl Clone for PathPattern
Source§fn clone(&self) -> PathPattern
fn clone(&self) -> PathPattern
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · 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 PathPattern
impl Debug for PathPattern
Source§impl Display for PathPattern
impl Display for PathPattern
Source§impl Hash for PathPattern
impl Hash for PathPattern
Source§impl PartialEq for PathPattern
impl PartialEq for PathPattern
Source§fn eq(&self, other: &PathPattern) -> bool
fn eq(&self, other: &PathPattern) -> bool
Tests for
self and other values to be equal, and is used by ==.impl Eq for PathPattern
impl StructuralPartialEq for PathPattern
Auto Trait Implementations§
impl Freeze for PathPattern
impl RefUnwindSafe for PathPattern
impl Send for PathPattern
impl Sync for PathPattern
impl Unpin for PathPattern
impl UnsafeUnpin for PathPattern
impl UnwindSafe for PathPattern
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