Enum combine::error::Commit[][src]

pub enum Commit<T> {
    Commit(T),
    Peek(T),
}
Expand description

Enum used to indicate if a parser committed any items of the stream it was given as an input.

This is used by parsers such as or and choice to determine if they should try to parse with another parser as they will only be able to provide good error reporting if the preceding parser did not commit to the parse.

Variants

Commit(T)

Constructor indicating that the parser has committed to this parse. If a parser after this fails, other parser alternatives will not be attempted (CommitErr will be returned)

Peek(T)

Constructor indicating that the parser has not committed to this parse. If a parser after this fails, other parser alternatives will be attempted (EmptyErr will be returned)

Implementations

Returns true if self is peek.

Extracts the contained value.

Converts self into the Commit state.

Converts self into the Peek state.

Maps over the contained value without changing the committed state.

Combines the Commit flags from self and the result of f.

Peek    <> Peek    -> Peek
Commit <> Peek    -> Commit
Peek    <> Commit -> Commit
Commit <> Commit -> Commit
//Parses a character of string literal and handles the escaped characters \\ and \" as \
//and " respectively
fn char<Input>(input: &mut Input) -> StdParseResult<char, Input>
    where Input: Stream<Token = char>,
          Input::Error: ParseError<Input::Token, Input::Range, Input::Position>,
{
    let (c, committed) = satisfy(|c| c != '"').parse_stream(input).into_result()?;
    match c {
        //Since the `char` parser has already committed some of the input `combine` is used
        //propagate the committed state to the next part of the parser
        '\\' => committed.combine(|_| {
            satisfy(|c| c == '"' || c == '\\')
                .map(|c| {
                    match c {
                        '"' => '"',
                        '\\' => '\\',
                        c => c
                    }
                })
                .parse_stream(input)
                .into_result()
            }),
        _ => Ok((c, committed))
    }
}
let result = many(parser(char))
    .easy_parse(r#"abc\"\\"#);
assert_eq!(result, Ok((r#"abc"\"#.to_string(), "")));
}

Trait Implementations

Performs the conversion.

Performs the conversion.

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.