Enum jj_lib::str_util::StringPattern
source · pub enum StringPattern {
Exact(String),
Glob(Pattern),
Substring(String),
}
Expand description
Pattern to be tested against string property like commit description or branch name.
Variants§
Exact(String)
Matches strings exactly equal to string
.
Glob(Pattern)
Unix-style shell wildcard pattern.
Substring(String)
Matches strings that contain substring
.
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:”,
“glob:”, or “substring:”, 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 glob(src: &str) -> Result<Self, StringPatternParseError>
pub fn glob(src: &str) -> Result<Self, StringPatternParseError>
Parses the given string as glob pattern.
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 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.
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
source§impl Display for StringPattern
impl Display for StringPattern
source§impl PartialEq for StringPattern
impl PartialEq for StringPattern
source§fn eq(&self, other: &StringPattern) -> bool
fn eq(&self, other: &StringPattern) -> bool
self
and other
values to be equal, and is used
by ==
.