pub struct Pattern {
pub text: BString,
pub mode: Mode,
pub first_wildcard_pos: Option<usize>,
pub base_path: Option<BString>,
}
Expand description
A glob pattern at a particular base path.
This closely models how patterns appear in a directory hierarchy of include or attribute files.
Fields
text: BString
the actual pattern bytes
mode: Mode
Additional information to help accelerate pattern matching.
first_wildcard_pos: Option<usize>
The position in text
with the first wildcard character, or None
if there is no wildcard at all.
base_path: Option<BString>
The relative base at which this pattern resides, with trailing slash, using slashes as path separator.
If None
, the pattern is considered to be at the root of the repository.
Implementations
sourceimpl Pattern
impl Pattern
sourcepub fn from_bytes(text: &[u8]) -> Option<Self>
pub fn from_bytes(text: &[u8]) -> Option<Self>
Parse the given text
as pattern, or return None
if text
was empty.
sourcepub fn is_negative(&self) -> bool
pub fn is_negative(&self) -> bool
Return true if a match is negated.
sourcepub fn with_base(self, path: impl Into<BString>) -> Self
pub fn with_base(self, path: impl Into<BString>) -> Self
Set the base path of the pattern. Must be a slash-separated relative path with a trailing slash.
Use this upon creation of the pattern when the source file is known.
sourcepub fn matches_repo_relative_path<'a>(
&self,
path: impl Into<&'a BStr>,
basename_start_pos: Option<usize>,
is_dir: bool,
case: Case
) -> bool
pub fn matches_repo_relative_path<'a>(
&self,
path: impl Into<&'a BStr>,
basename_start_pos: Option<usize>,
is_dir: bool,
case: Case
) -> bool
Match the given path
which takes slashes (and only slashes) literally, and is relative to the repository root.
Note that path
is assumed to be relative to the repository, and that our base_path
is assumed to contain path
.
We may take various shortcuts which is when basename_start_pos
and is_dir
come into play.
basename_start_pos
is the index at which the path
’s basename starts.
Lastly, case
folding can be configured as well.
Note that this method uses shortcuts to accelerate simple patterns.
sourcepub fn matches<'a>(&self, value: impl Into<&'a BStr>, mode: Mode) -> bool
pub fn matches<'a>(&self, value: impl Into<&'a BStr>, mode: Mode) -> bool
See if value
matches this pattern in the given mode
.
mode
can identify value
as path which won’t match the slash character, and can match
strings with cases ignored as well. Note that the case folding performed here is ASCII only.
Note that this method uses some shortcuts to accelerate simple patterns.
Trait Implementations
sourceimpl Ord for Pattern
impl Ord for Pattern
sourceimpl PartialOrd<Pattern> for Pattern
impl PartialOrd<Pattern> for Pattern
sourcefn partial_cmp(&self, other: &Pattern) -> Option<Ordering>
fn partial_cmp(&self, other: &Pattern) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
1.0.0 · sourcefn lt(&self, other: &Rhs) -> bool
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
impl Eq for Pattern
impl StructuralEq for Pattern
impl StructuralPartialEq for Pattern
Auto Trait Implementations
impl RefUnwindSafe for Pattern
impl Send for Pattern
impl Sync for Pattern
impl Unpin for Pattern
impl UnwindSafe for Pattern
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more