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

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

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

impl<T> Commit<T>[src]

pub fn is_peek(&self) -> bool[src]

Returns true if self is peek.

pub fn into_inner(self) -> T[src]

Extracts the contained value.

pub fn into_commit(self) -> Commit<T>[src]

Converts self into the Commit state.

pub fn into_peek(self) -> Commit<T>[src]

Converts self into the Peek state.

pub fn map<F, U>(self, f: F) -> Commit<U> where
    F: FnOnce(T) -> U, 
[src]

Maps over the contained value without changing the committed state.

pub fn merge(&self, current: Commit<T>) -> Commit<T>[src]

pub fn combine<F, U, E>(self, f: F) -> StdParseResult2<U, E> where
    F: FnOnce(T) -> StdParseResult2<U, E>, 
[src]

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(), "")));
}

pub fn combine_commit<F, U, E>(self, f: F) -> ParseResult<U, E> where
    F: FnOnce(T) -> ParseResult<U, E>, 
[src]

Trait Implementations

impl<T> AsMut<T> for Commit<T>[src]

impl<T> AsRef<T> for Commit<T>[src]

impl<T: Clone> Clone for Commit<T>[src]

impl<T: Copy> Copy for Commit<T>[src]

impl<T: Debug> Debug for Commit<T>[src]

impl<T: PartialEq> PartialEq<Commit<T>> for Commit<T>[src]

impl<T> StructuralPartialEq for Commit<T>[src]

Auto Trait Implementations

impl<T> RefUnwindSafe for Commit<T> where
    T: RefUnwindSafe

impl<T> Send for Commit<T> where
    T: Send

impl<T> Sync for Commit<T> where
    T: Sync

impl<T> Unpin for Commit<T> where
    T: Unpin

impl<T> UnwindSafe for Commit<T> where
    T: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.