Enum combine::primitives::Consumed [] [src]

pub enum Consumed<T> {
    Consumed(T),
    Empty(T),
}

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

Variants

Constructor indicating that the parser has consumed elements

Constructor indicating that the parser did not consume any elements

Methods

impl<T> Consumed<T>
[src]

Returns true if self is empty

Extracts the contained value

Converts self into the Consumed state

Converts self into theEmpty state

Maps over the contained value without changing the consumed state

Combines the Consumed flags from self and the result of f

//Parses a character of string literal and handles the escaped characters \\ and \" as \
//and " respectively
fn char(input: &str) -> ParseResult<char, &str> {
    let (c, input) = try!(satisfy(|c| c != '"').parse_stream(input));
    match c {
        //Since the `char` parser has already consumed some of the input `combine` is used
        //propagate the consumed state to the next part of the parser
        '\\' => input.combine(|input| {
            satisfy(|c| c == '"' || c == '\\')
                .map(|c| {
                    match c {
                        '"' => '"',
                        '\\' => '\\',
                        c => c
                    }
                })
                .parse_stream(input)
            }),
        _ => Ok((c, input))
    }
}
let result = many(parser(char))
    .parse(r#"abc\"\\"#);
assert_eq!(result, Ok((r#"abc"\"#.to_string(), "")));
}

Trait Implementations

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

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

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

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

This method tests for !=.

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

Formats the value using the given formatter.

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