Trait Pattern

Source
pub trait Pattern {
    // Required methods
    fn immediate_match<I: Input>(&self, input: I) -> Result<(I, I), I>;
    fn trailing_match<I: Input>(&self, input: I) -> Result<(I, I), I>;
    fn first_match<I: Input>(&self, input: I) -> Result<(I, (I, I)), I>;
    fn first_match_ex<I: Input>(&self, input: I) -> Result<(I, (I, I)), I>;

    // Provided methods
    fn immediate_matches<I: Input>(&self, input: I) -> (I, I) { ... }
    fn immediate_matches_counted<I: Input>(&self, input: I) -> (I, (I, usize)) { ... }
    fn trailing_matches_counted<I: Input>(&self, input: I) -> (I, usize) { ... }
    fn by_ref(&self) -> impl Pattern + Copy { ... }
}
Expand description

This trait represents an object that can be matched onto a string. This includes functions, characters, [arrays of] characters, strings, but also custom patterns like NotEscaped

Required Methods§

Source

fn immediate_match<I: Input>(&self, input: I) -> Result<(I, I), I>

The return values are (rest of the input, matched fragment at the beginning).

§Errors

In the case of no match, the original input is returned as the Err variant.

Used by parse.

Source

fn trailing_match<I: Input>(&self, input: I) -> Result<(I, I), I>

Like Pattern::immediate_match, but matches at the end of input. The return values are (the input before the match, the match)

§Errors

In the case of no match, the original input is returned as the Err variant.

Used by the Pattern impl of NotEscaped

Source

fn first_match<I: Input>(&self, input: I) -> Result<(I, (I, I)), I>

The return values are (the match + rest of the input, (string before the match, the match)).

§Errors

Returns the provided input unchanged in the Err variant if there’s no match.

Used by parse_until.

Source

fn first_match_ex<I: Input>(&self, input: I) -> Result<(I, (I, I)), I>

Like Pattern::first_match, but the match is excluded from the rest of the input.

§Errors

Returns the provided input unchanged in the Err variant if there’s no match.

Used by parse_until_ex.

Provided Methods§

Source

fn immediate_matches<I: Input>(&self, input: I) -> (I, I)

The return values are (rest of the input, contiguous matched fragments from the beginning).

0 is also a valid number of matches.

Used by parse_while

Source

fn immediate_matches_counted<I: Input>(&self, input: I) -> (I, (I, usize))

Like Pattern::immediate_matches, but also counts the number of matches.

Used by the Pattern impl of NotEscaped

Source

fn trailing_matches_counted<I: Input>(&self, input: I) -> (I, usize)

Like Pattern::immediate_matches_counted, but matches at the end of input, and doesn’t return the matched fragment of the input.

Used by the Pattern impl of NotEscaped

Source

fn by_ref(&self) -> impl Pattern + Copy

Get the pattern by reference to avoid moving it, which will happen in generic code

Do not override this method.

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.

Implementations on Foreign Types§

Source§

impl Pattern for &str

Source§

fn immediate_match<I: Input>(&self, input: I) -> Result<(I, I), I>

Source§

fn immediate_matches<I: Input>(&self, input: I) -> (I, I)

Source§

fn immediate_matches_counted<I: Input>(&self, input: I) -> (I, (I, usize))

Source§

fn trailing_match<I: Input>(&self, input: I) -> Result<(I, I), I>

Source§

fn trailing_matches_counted<I: Input>(&self, input: I) -> (I, usize)

Source§

fn first_match<I: Input>(&self, input: I) -> Result<(I, (I, I)), I>

Source§

fn first_match_ex<I: Input>(&self, input: I) -> Result<(I, (I, I)), I>

Source§

impl Pattern for char

Source§

fn immediate_match<I: Input>(&self, input: I) -> Result<(I, I), I>

Source§

fn immediate_matches<I: Input>(&self, input: I) -> (I, I)

Source§

fn immediate_matches_counted<I: Input>(&self, input: I) -> (I, (I, usize))

Source§

fn trailing_match<I: Input>(&self, input: I) -> Result<(I, I), I>

Source§

fn trailing_matches_counted<I: Input>(&self, input: I) -> (I, usize)

Source§

fn first_match<I: Input>(&self, input: I) -> Result<(I, (I, I)), I>

Source§

fn first_match_ex<I: Input>(&self, input: I) -> Result<(I, (I, I)), I>

Implementors§

Source§

impl Pattern for AnyChar

Source§

impl<F: Fn(&char) -> bool> Pattern for F

Source§

impl<Prefix: Pattern, Inner: Pattern> Pattern for NotEscaped<Prefix, Inner>