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.
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 consume any tokens.
Variants
Consumed(T)
Constructor indicating that the parser has consumed elements
Empty(T)
Constructor indicating that the parser did not consume any elements
Methods
impl<T> Consumed<T>
[src]
fn is_empty(&self) -> bool
Returns true if self
is empty.
fn into_inner(self) -> T
Extracts the contained value.
fn as_consumed(self) -> Consumed<T>
: Renamed to into_consumed
Converts self
into the Consumed
state.
fn into_consumed(self) -> Consumed<T>
Converts self
into the Consumed
state.
fn as_empty(self) -> Consumed<T>
: Renamed to into_empty
Converts self
into the Empty
state.
fn into_empty(self) -> Consumed<T>
Converts self
into the Empty
state.
fn map<F, U>(self, f: F) -> Consumed<U> where
F: FnOnce(T) -> U,
F: FnOnce(T) -> U,
Maps over the contained value without changing the consumed state.
fn merge(&self, current: Consumed<T>) -> Consumed<T>
fn combine<F, U, I>(self, f: F) -> ParseResult<U, I> where
F: FnOnce(T) -> ParseResult<U, I>,
I: StreamOnce,
F: FnOnce(T) -> ParseResult<U, I>,
I: StreamOnce,
Combines the Consumed
flags from self
and the result of f
.
Empty <> Empty -> Empty
Consumed <> Empty -> Consumed
Empty <> Consumed -> Consumed
Consumed <> Consumed -> Consumed
//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(), ""))); }
fn combine_consumed<F, U, I>(self, f: F) -> ConsumedResult<U, I> where
F: FnOnce(T) -> ConsumedResult<U, I>,
I: StreamOnce,
F: FnOnce(T) -> ConsumedResult<U, I>,
I: StreamOnce,
Trait Implementations
impl<T: Clone> Clone for Consumed<T>
[src]
fn clone(&self) -> Consumed<T>
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0
Performs copy-assignment from source
. Read more
impl<T: PartialEq> PartialEq for Consumed<T>
[src]
fn eq(&self, __arg_0: &Consumed<T>) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, __arg_0: &Consumed<T>) -> bool
This method tests for !=
.
impl<T: Debug> Debug for Consumed<T>
[src]
impl<T: Copy> Copy for Consumed<T>
[src]
impl<T> AsMut<T> for Consumed<T>
[src]
fn as_mut(&mut self) -> &mut T
Performs the conversion.
impl<T> AsRef<T> for Consumed<T>
[src]
fn as_ref(&self) -> &T
Performs the conversion.