pub trait Matcher<I: HaystackItem>: Debug + Default {
// Required method
fn matches<'a, H: HaystackOf<'a, I>>(hay: &mut H) -> bool;
// Provided methods
fn all_matches<'a, H: HaystackOf<'a, I>>(hay: &mut H) -> Vec<usize> { ... }
fn captures<'a, H: HaystackOf<'a, I>>(
hay: &mut H,
caps: &mut IndexedCaptures,
) -> bool { ... }
fn all_captures<'a, H: HaystackOf<'a, I>>(
hay: &mut H,
caps: &mut IndexedCaptures,
) -> Vec<(usize, IndexedCaptures)> { ... }
}Required Methods§
Sourcefn matches<'a, H: HaystackOf<'a, I>>(hay: &mut H) -> bool
fn matches<'a, H: HaystackOf<'a, I>>(hay: &mut H) -> bool
Checks if the start of the haystack contains a match for this Matcher. If this method
successfully matches the start of the haystack, hay is progressed so that hay.item()
hasn’t been matched yet. On a fail, the state of hay is undefined.
Provided Methods§
Sourcefn all_matches<'a, H: HaystackOf<'a, I>>(hay: &mut H) -> Vec<usize>
fn all_matches<'a, H: HaystackOf<'a, I>>(hay: &mut H) -> Vec<usize>
Produces a Vec of all valid haystack states produced as the result of a valid match at the
start of hay, used to implement backtracking. The Vec is produced in reverse priority
order, so the last match has the highest priority. After calling all_matches, the state of
hay itself is undefined.
§Required
This method needs to be implemented by all Matchers that can match more than one string
of characters from a haystack.
Sourcefn captures<'a, H: HaystackOf<'a, I>>(
hay: &mut H,
caps: &mut IndexedCaptures,
) -> bool
fn captures<'a, H: HaystackOf<'a, I>>( hay: &mut H, caps: &mut IndexedCaptures, ) -> bool
Checks if the start of the haystack contains a match for this Matcher, writing any groups
to caps. Similar to matches, this method progresses hay and caps on a success. On
a fail, they have undefined states.
§Required
This method needs to be implemented for capturing groups or any type that holds other
Matchers, so that it can redirect to the relevant capture methods.
Sourcefn all_captures<'a, H: HaystackOf<'a, I>>(
hay: &mut H,
caps: &mut IndexedCaptures,
) -> Vec<(usize, IndexedCaptures)>
fn all_captures<'a, H: HaystackOf<'a, I>>( hay: &mut H, caps: &mut IndexedCaptures, ) -> Vec<(usize, IndexedCaptures)>
Produces a Vec of all valid captures (and accompanying haystack states) present at the start
of hay. Used to implement backtracking for capturing methods. As with
all_matches, the resulting Vec is produced in reverse priority
order. After calling all_captures, the state of hay and caps are undefined.
§Required
This method needs to be implemented for any type that also implements
captures and all_matches.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.