pub enum StringPattern {
Exact(String),
ExactI(String),
Substring(String),
SubstringI(String),
Glob(GlobPattern),
GlobI(GlobPattern),
Regex(Regex),
RegexI(Regex),
}
Expand description
Pattern to be tested against string property like commit description or bookmark name.
Variants§
Exact(String)
Matches strings exactly.
ExactI(String)
Matches strings case‐insensitively.
Substring(String)
Matches strings that contain a substring.
SubstringI(String)
Matches strings that case‐insensitively contain a substring.
Glob(GlobPattern)
Matches with a Unix‐style shell wildcard pattern.
GlobI(GlobPattern)
Matches with a case‐insensitive Unix‐style shell wildcard pattern.
Regex(Regex)
Matches substrings with a regular expression.
RegexI(Regex)
Matches substrings with a case‐insensitive regular expression.
Implementations§
Source§impl StringPattern
impl StringPattern
Sourcepub const fn everything() -> Self
pub const fn everything() -> Self
Pattern that matches any string.
Sourcepub fn parse(src: &str) -> Result<StringPattern, StringPatternParseError>
pub fn parse(src: &str) -> Result<StringPattern, StringPatternParseError>
Parses the given string as a StringPattern
. Everything before the
first “:” is considered the string’s prefix. If the prefix is
“exact[-i]:”, “glob[-i]:”, or “substring[-i]:”, a pattern of the
specified kind is returned. Returns an error if the string has an
unrecognized prefix. Otherwise, a StringPattern::Exact
is
returned.
Sourcepub fn exact_i(src: impl Into<String>) -> Self
pub fn exact_i(src: impl Into<String>) -> Self
Constructs a pattern that matches case‐insensitively.
Sourcepub fn substring(src: impl Into<String>) -> Self
pub fn substring(src: impl Into<String>) -> Self
Constructs a pattern that matches a substring.
Sourcepub fn substring_i(src: impl Into<String>) -> Self
pub fn substring_i(src: impl Into<String>) -> Self
Constructs a pattern that case‐insensitively matches a substring.
Sourcepub fn glob(src: &str) -> Result<Self, StringPatternParseError>
pub fn glob(src: &str) -> Result<Self, StringPatternParseError>
Parses the given string as a glob pattern.
Sourcepub fn glob_i(src: &str) -> Result<Self, StringPatternParseError>
pub fn glob_i(src: &str) -> Result<Self, StringPatternParseError>
Parses the given string as a case‐insensitive glob pattern.
Sourcepub fn regex(src: &str) -> Result<Self, StringPatternParseError>
pub fn regex(src: &str) -> Result<Self, StringPatternParseError>
Parses the given string as a regular expression.
Sourcepub fn regex_i(src: &str) -> Result<Self, StringPatternParseError>
pub fn regex_i(src: &str) -> Result<Self, StringPatternParseError>
Parses the given string as a case-insensitive regular expression.
Sourcepub fn from_str_kind(
src: &str,
kind: &str,
) -> Result<Self, StringPatternParseError>
pub fn from_str_kind( src: &str, kind: &str, ) -> Result<Self, StringPatternParseError>
Parses the given string as a pattern of the specified kind
.
Sourcepub fn as_exact(&self) -> Option<&str>
pub fn as_exact(&self) -> Option<&str>
Returns a literal pattern if this should match input strings exactly.
This can be used to optimize map lookup by exact key.
Sourcepub fn to_glob(&self) -> Option<Cow<'_, str>>
pub fn to_glob(&self) -> Option<Cow<'_, str>>
Converts this pattern to a glob string. Returns None
if the pattern
can’t be represented as a glob.
Sourcepub fn matches(&self, haystack: &str) -> bool
pub fn matches(&self, haystack: &str) -> bool
Returns true if this pattern matches the haystack
.
When matching against a case‐insensitive pattern, only ASCII case differences are currently folded. This may change in the future.
Sourcepub fn filter_btree_map<'a, 'b, K: Borrow<str> + Ord, V>(
&'b self,
map: &'a BTreeMap<K, V>,
) -> impl Iterator<Item = (&'a K, &'a V)> + use<'a, 'b, K, V>
pub fn filter_btree_map<'a, 'b, K: Borrow<str> + Ord, V>( &'b self, map: &'a BTreeMap<K, V>, ) -> impl Iterator<Item = (&'a K, &'a V)> + use<'a, 'b, K, V>
Iterates entries of the given map
whose string keys match this
pattern.
Sourcepub fn filter_btree_map_as_deref<'a, 'b, K, V>(
&'b self,
map: &'a BTreeMap<K, V>,
) -> impl Iterator<Item = (&'a K, &'a V)> + use<'a, 'b, K, V>
pub fn filter_btree_map_as_deref<'a, 'b, K, V>( &'b self, map: &'a BTreeMap<K, V>, ) -> impl Iterator<Item = (&'a K, &'a V)> + use<'a, 'b, K, V>
Iterates entries of the given map
whose string-like keys match this
pattern.
The borrowed key type is constrained by the Deref::Target
. It must be
convertible to/from str
.
Trait Implementations§
Source§impl Clone for StringPattern
impl Clone for StringPattern
Source§fn clone(&self) -> StringPattern
fn clone(&self) -> StringPattern
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Debug for StringPattern
impl Debug for StringPattern
Auto Trait Implementations§
impl Freeze for StringPattern
impl RefUnwindSafe for StringPattern
impl Send for StringPattern
impl Sync for StringPattern
impl Unpin for StringPattern
impl UnwindSafe for StringPattern
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> 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>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more