pub struct Pattern<S = usize, A = DenseDFA<Vec<S>, S>> where
S: StateID,
A: DFA<ID = S>, { /* private fields */ }
Expand description
A compiled match pattern that can match multipe inputs, or return a
Matcher
that matches a single input.
Implementations
sourceimpl<S, A> Pattern<S, A> where
S: StateID,
A: DFA<ID = S>,
Self: for<'a> ToMatcher<'a, S>,
impl<S, A> Pattern<S, A> where
S: StateID,
A: DFA<ID = S>,
Self: for<'a> ToMatcher<'a, S>,
sourcepub fn matches(&self, s: &impl AsRef<str>) -> bool
pub fn matches(&self, s: &impl AsRef<str>) -> bool
Returns true
if this pattern matches the given string.
sourcepub fn debug_matches(&self, d: &impl Debug) -> bool
pub fn debug_matches(&self, d: &impl Debug) -> bool
Returns true
if this pattern matches the formatted output of the given
type implementing fmt::Debug
.
For example:
use matchers::Pattern;
#[derive(Debug)]
pub struct Hello {
to: &'static str,
}
let pattern = Pattern::new(r#"Hello \{ to: "W[^"]*" \}"#).unwrap();
let hello_world = Hello { to: "World" };
assert!(pattern.debug_matches(&hello_world));
let hello_sf = Hello { to: "San Francisco" };
assert_eq!(pattern.debug_matches(&hello_sf), false);
let hello_washington = Hello { to: "Washington" };
assert!(pattern.debug_matches(&hello_washington));
sourcepub fn display_matches(&self, d: &impl Display) -> bool
pub fn display_matches(&self, d: &impl Display) -> bool
Returns true
if this pattern matches the formatted output of the given
type implementing fmt::Display
.
For example:
use matchers::Pattern;
#[derive(Debug)]
pub struct Hello {
to: &'static str,
}
impl fmt::Display for Hello {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "Hello {}", self.to)
}
}
let pattern = Pattern::new("Hello [Ww].+").unwrap();
let hello_world = Hello { to: "world" };
assert!(pattern.display_matches(&hello_world));
assert_eq!(pattern.debug_matches(&hello_world), false);
let hello_sf = Hello { to: "San Francisco" };
assert_eq!(pattern.display_matches(&hello_sf), false);
let hello_washington = Hello { to: "Washington" };
assert!(pattern.display_matches(&hello_washington));
sourcepub fn read_matches(&self, io: impl Read) -> Result<bool>
pub fn read_matches(&self, io: impl Read) -> Result<bool>
Returns either a bool
indicating whether or not this pattern matches the
data read from the provided io::Read
stream, or an io::Error
if an
error occurred reading from the stream.
Trait Implementations
Auto Trait Implementations
impl<S, A> RefUnwindSafe for Pattern<S, A> where
A: RefUnwindSafe,
impl<S, A> Send for Pattern<S, A> where
A: Send,
impl<S, A> Sync for Pattern<S, A> where
A: Sync,
impl<S, A> Unpin for Pattern<S, A> where
A: Unpin,
impl<S, A> UnwindSafe for Pattern<S, A> where
A: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub 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.
sourcepub fn to_owned(&self) -> T
pub fn to_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. Read more
sourcepub fn clone_into(&self, target: &mut T)
pub fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more