Matcher

Trait Matcher 

Source
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§

Source

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§

Source

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.

Source

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.

Source

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.

Implementors§

Source§

impl<I: HaystackItem> Matcher<I> for Always

Source§

impl<I: HaystackItem> Matcher<I> for Beginning

Source§

impl<I: HaystackItem> Matcher<I> for End

Source§

impl<I: HaystackItem, A: Matcher<I>, B: Matcher<I>> Matcher<I> for Or<I, A, B>

Source§

impl<I: HaystackItem, A: Matcher<I>, B: Matcher<I>> Matcher<I> for Then<I, A, B>

Source§

impl<I: HaystackItem, A: Matcher<I>, const N: usize> Matcher<I> for CaptureGroup<I, A, N>

Source§

impl<I: HaystackItem, A: Matcher<I>, const N: usize> Matcher<I> for QuantifierN<I, A, N>

Source§

impl<I: HaystackItem, A: Matcher<I>, const N: usize> Matcher<I> for QuantifierNOrMore<I, A, N>

Source§

impl<I: HaystackItem, A: Matcher<I>, const N: usize, const M: usize> Matcher<I> for QuantifierNToM<I, A, N, M>

Source§

impl<I: HaystackItem, Q: Matcher<I>, T: Matcher<I>> Matcher<I> for QuantifierThen<I, Q, T>

Source§

impl<Z: HaystackItem, A: Matcher<Z>, B: Matcher<Z>, C: Matcher<Z>, D: Matcher<Z>> Matcher<Z> for Or4<Z, A, B, C, D>

Source§

impl<Z: HaystackItem, A: Matcher<Z>, B: Matcher<Z>, C: Matcher<Z>, D: Matcher<Z>> Matcher<Z> for Then4<Z, A, B, C, D>

Source§

impl<Z: HaystackItem, A: Matcher<Z>, B: Matcher<Z>, C: Matcher<Z>, D: Matcher<Z>, E: Matcher<Z>, F: Matcher<Z>, G: Matcher<Z>, H: Matcher<Z>> Matcher<Z> for Or8<Z, A, B, C, D, E, F, G, H>

Source§

impl<Z: HaystackItem, A: Matcher<Z>, B: Matcher<Z>, C: Matcher<Z>, D: Matcher<Z>, E: Matcher<Z>, F: Matcher<Z>, G: Matcher<Z>, H: Matcher<Z>> Matcher<Z> for Then8<Z, A, B, C, D, E, F, G, H>

Source§

impl<Z: HaystackItem, A: Matcher<Z>, B: Matcher<Z>, C: Matcher<Z>, D: Matcher<Z>, E: Matcher<Z>, F: Matcher<Z>, G: Matcher<Z>, H: Matcher<Z>, I: Matcher<Z>, J: Matcher<Z>, K: Matcher<Z>, L: Matcher<Z>, M: Matcher<Z>, N: Matcher<Z>, O: Matcher<Z>, P: Matcher<Z>> Matcher<Z> for Or16<Z, A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P>

Source§

impl<Z: HaystackItem, A: Matcher<Z>, B: Matcher<Z>, C: Matcher<Z>, D: Matcher<Z>, E: Matcher<Z>, F: Matcher<Z>, G: Matcher<Z>, H: Matcher<Z>, I: Matcher<Z>, J: Matcher<Z>, K: Matcher<Z>, L: Matcher<Z>, M: Matcher<Z>, N: Matcher<Z>, O: Matcher<Z>, P: Matcher<Z>> Matcher<Z> for Then16<Z, A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P>

Source§

impl<const A: char, const B: char> Matcher<char> for ScalarRange<A, B>

Source§

impl<const A: u8, const B: u8> Matcher<u8> for ByteRange<A, B>

Source§

impl<const N: char> Matcher<char> for Scalar<N>

Source§

impl<const N: u8> Matcher<u8> for Byte<N>