Struct matchers::Pattern [−][src]
A compiled match pattern that can match multipe inputs, or return a
Matcher
that matches a single input.
Implementations
impl Pattern
[src]
pub fn new(pattern: &str) -> Result<Self, Error>
[src]
Returns a new Pattern
for the given regex, or an error if the regex
was invalid.
impl<S, A> Pattern<S, A> where
S: StateID,
A: DFA<ID = S>,
Self: for<'a> ToMatcher<'a, S>,
[src]
S: StateID,
A: DFA<ID = S>,
Self: for<'a> ToMatcher<'a, S>,
pub fn matches(&self, s: &impl AsRef<str>) -> bool
[src]
Returns true
if this pattern matches the given string.
pub fn debug_matches(&self, d: &impl Debug) -> bool
[src]
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));
pub fn display_matches(&self, d: &impl Display) -> bool
[src]
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));
pub fn read_matches(&self, io: impl Read) -> Result<bool>
[src]
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
impl<S: Clone, A: Clone> Clone for Pattern<S, A> where
S: StateID,
A: DFA<ID = S>,
[src]
S: StateID,
A: DFA<ID = S>,
impl<S: Debug, A: Debug> Debug for Pattern<S, A> where
S: StateID,
A: DFA<ID = S>,
[src]
S: StateID,
A: DFA<ID = S>,
impl FromStr for Pattern
[src]
type Err = Error
The associated error which can be returned from parsing.
fn from_str(s: &str) -> Result<Self, Self::Err>
[src]
impl<'a, S> ToMatcher<'a, S> for Pattern<S, DenseDFA<Vec<S>, S>> where
S: StateID + 'a,
[src]
S: StateID + 'a,
impl<'a, S> ToMatcher<'a, S> for Pattern<S, SparseDFA<Vec<u8>, S>> where
S: StateID + 'a,
[src]
S: StateID + 'a,
Auto Trait Implementations
impl<S, A> RefUnwindSafe for Pattern<S, A> where
A: RefUnwindSafe,
A: RefUnwindSafe,
impl<S, A> Send for Pattern<S, A> where
A: Send,
A: Send,
impl<S, A> Sync for Pattern<S, A> where
A: Sync,
A: Sync,
impl<S, A> Unpin for Pattern<S, A> where
A: Unpin,
A: Unpin,
impl<S, A> UnwindSafe for Pattern<S, A> where
A: UnwindSafe,
A: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,