pub trait Pattern {
// Required method
fn eval(&self, input: &[u8]) -> Option<usize>;
// Provided methods
fn then<P>(self, other: P) -> Sequence<Self, P>
where Self: Sized,
P: Pattern { ... }
fn and<P>(self, other: P) -> Composition<Self, P>
where Self: Sized,
P: Pattern { ... }
fn or<P>(self, other: P) -> Choice<Self, P>
where Self: Sized,
P: Pattern { ... }
}Expand description
Expresses that the implementing can be used to match a slice of bytes.
Required Methods§
Provided Methods§
Sourcefn then<P>(self, other: P) -> Sequence<Self, P>
fn then<P>(self, other: P) -> Sequence<Self, P>
Returns a new pattern that will match if self and other match in sequence.
use bparse::Pattern;
let pattern = "a".then("b");
assert_eq!(pattern.eval(b"abc"), Some(2));Sourcefn and<P>(self, other: P) -> Composition<Self, P>
fn and<P>(self, other: P) -> Composition<Self, P>
Returns a new pattern that will match if both self and other match.
Unlike Pattern::then, self and other are evaluated against the same input.
use bparse::{Pattern, hex, alpha};
let pattern = hex().and(alpha());
assert_eq!(pattern.eval(b"a"), Some(1));
assert_eq!(pattern.eval(b"3"), None);