[−][src]Enum combine::error::Consumed
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
Constructor indicating that the parser has consumed elements
Constructor indicating that the parser did not consume any elements
Methods
impl<T> Consumed<T>
[src]
pub fn is_empty(&self) -> bool
[src]
Returns true if self
is empty.
pub fn into_inner(self) -> T
[src]
Extracts the contained value.
pub fn into_consumed(self) -> Consumed<T>
[src]
Converts self
into the Consumed
state.
pub fn into_empty(self) -> Consumed<T>
[src]
Converts self
into the Empty
state.
pub fn map<F, U>(self, f: F) -> Consumed<U> where
F: FnOnce(T) -> U,
[src]
F: FnOnce(T) -> U,
Maps over the contained value without changing the consumed state.
pub fn merge(&self, current: Consumed<T>) -> Consumed<T>
[src]
pub fn combine<F, U, E>(self, f: F) -> StdParseResult2<U, E> where
F: FnOnce(T) -> StdParseResult2<U, E>,
[src]
F: FnOnce(T) -> StdParseResult2<U, E>,
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>(input: &mut Input) -> StdParseResult<char, Input> where Input: Stream<Token = char>, Input::Error: ParseError<Input::Token, Input::Range, Input::Position>, { let (c, consumed) = satisfy(|c| c != '"').parse_stream(input).into_result()?; 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 '\\' => consumed.combine(|_| { satisfy(|c| c == '"' || c == '\\') .map(|c| { match c { '"' => '"', '\\' => '\\', c => c } }) .parse_stream(input) .into_result() }), _ => Ok((c, consumed)) } } let result = many(parser(char)) .easy_parse(r#"abc\"\\"#); assert_eq!(result, Ok((r#"abc"\"#.to_string(), ""))); }
pub fn combine_consumed<F, U, E>(self, f: F) -> ParseResult<U, E> where
F: FnOnce(T) -> ParseResult<U, E>,
[src]
F: FnOnce(T) -> ParseResult<U, E>,
Trait Implementations
impl<T> AsRef<T> for Consumed<T>
[src]
impl<T> AsMut<T> for Consumed<T>
[src]
impl<T: Clone> Clone for Consumed<T>
[src]
impl<T: Copy> Copy for Consumed<T>
[src]
impl<T: PartialEq> PartialEq<Consumed<T>> for Consumed<T>
[src]
impl<T: Debug> Debug for Consumed<T>
[src]
Auto Trait Implementations
impl<T> Send for Consumed<T> where
T: Send,
T: Send,
impl<T> Sync for Consumed<T> where
T: Sync,
T: Sync,
impl<T> Unpin for Consumed<T> where
T: Unpin,
T: Unpin,
impl<T> UnwindSafe for Consumed<T> where
T: UnwindSafe,
T: UnwindSafe,
impl<T> RefUnwindSafe for Consumed<T> where
T: RefUnwindSafe,
T: RefUnwindSafe,
Blanket Implementations
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From<T> for T
[src]
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
ⓘImportant traits for &'_ mut Wfn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,