pub enum Matchable {
Str(String),
Regex(Regex),
}Expand description
Matchable is a wrapper for a plain string or a regex, and it’s used to check matching.
When checking if a text is matching or not, if it’s a plain string, it will check whether two strings are equal or not; if it’s a regex, it will check whether that text matches the regex or not.
When deserializing by Serde,
if the value starts with a slash /, and it ends with a slash / with optional regex flags,
like "/abcd/" or "/abcd/i", it will be deserialized as a regex;
otherwise, it will be deserialized as a plain string.
Variants§
Implementations§
Source§impl Matchable
impl Matchable
Sourcepub fn is_match(&self, text: impl AsRef<str>) -> bool
pub fn is_match(&self, text: impl AsRef<str>) -> bool
Check whether a piece of text matches the Matchable or not.
use matchable::Matchable;
assert!(Matchable::Str("Abc".into()).is_match("Abc"));
assert!(!Matchable::Str("Abc".into()).is_match("abc"));
let re = regex::RegexBuilder::new("Abc")
.case_insensitive(true)
.build()
.unwrap();
assert!(Matchable::Regex(re).is_match("abc"));Trait Implementations§
impl Eq for Matchable
Auto Trait Implementations§
impl Freeze for Matchable
impl RefUnwindSafe for Matchable
impl Send for Matchable
impl Sync for Matchable
impl Unpin for Matchable
impl UnwindSafe for Matchable
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