pub trait Pattern {
// Required method
fn test<'i>(&self, input: &'i [u8]) -> Option<(&'i [u8], &'i [u8])>;
// Provided methods
fn or<P>(self, other: P) -> Or<Self, P>
where Self: Sized { ... }
fn and<P>(self, next: P) -> And<Self, P>
where Self: Sized { ... }
fn repeats<I: Into<Interval<usize>>>(self, count: I) -> Repeat<Self>
where Self: Sized { ... }
}Expand description
Expresses that the implementing type can be used to match a byte slice
Required Methods§
Provided Methods§
sourcefn or<P>(self, other: P) -> Or<Self, P>where
Self: Sized,
fn or<P>(self, other: P) -> Or<Self, P>where
Self: Sized,
Expresses an alternate pattern.
Returns a new pattern that will match an input slice if either self or other match it.
§Example
use bparse::Pattern;
let input = b"b";
let pattern = "a".or("b");
assert_eq!(b"b", pattern.test(input).unwrap().0);sourcefn and<P>(self, next: P) -> And<Self, P>where
Self: Sized,
fn and<P>(self, next: P) -> And<Self, P>where
Self: Sized,
Expreses a sequence of patterns
Returns a new pattern that will test an input slice against self and other in sequence,
feeding the remainder from the first match as the input to the second.
§Example
use bparse::Pattern;
let input = b"abc";
let pattern = "a".and("b").and("c");
assert_eq!(b"abc", pattern.test(input).unwrap().0);sourcefn repeats<I: Into<Interval<usize>>>(self, count: I) -> Repeat<Self>where
Self: Sized,
fn repeats<I: Into<Interval<usize>>>(self, count: I) -> Repeat<Self>where
Self: Sized,
Expresses pattern repetition
Returns a new pattern that will match an input slice if self can match count times
Anything that can be safely converted to an Interval can be used as an argument .
use bparse::{Pattern};
let input = b"ababab";
let pattern = "a".and("b").repeats(1..=2);
assert_eq!(b"abab", pattern.test(input).unwrap().0);