Enum flussab::Parsed[][src]

#[must_use]pub enum Parsed<T, E> {
    Res(Result<T, E>),
    Fallthrough,
}

Return type for recursive descent parser that can fall through to another parser on unexpected input.

If you have a parser that only fails irrecoverably, by returning a Result, you can use into to convert it to a Parsed value. Conversely, Parsed values can be converted into plain Result using or_give_up, making the Parsed value fall through to an unrecoverable error, or using optional making the parsed value optional.

Note that some of the methods of Parsed already have equivalent methods of the Result type in std. Some more methods are also implemented for Result by this crate, using the ResultExt trait. Finally some of the methods are only intended for parser that can fall through, and as such, they are not implemented for Result.

Variants

Res(Result<T, E>)

A successfully parsed value or an irrecoverable error.

When Res(Ok(v)) is returned, the value was parsed successfully and the input stream should be advanced past the parsed input.

When Res(Err(err)) is returned, either the initial input matched, but continued in an unexpected way or some other kind of runtime error occured. In this case the input stream points at the position of the unexpected input or the input causing an error.

Fallthrough

The input does not match the expected input of the parser.

This leaves the input stream unchanged, so that another parser can be tried.

Implementations

impl<T, E> Parsed<T, E>[src]

pub fn err_into<E2: From<E>>(self) -> Parsed<T, E2>[src]

Equivalent to map_err(From::from).

pub fn or_give_up(self, err: impl FnOnce() -> E) -> Result<T, E>[src]

Makes a parser fail irrecoverably when the current input did not match the expected input of the returning parser.

This makes the expected input of the parser returning this Parsed value a mandatory part of the input.

pub fn optional(self) -> Result<Option<T>, E>[src]

Returns None when the current input did not match the expected input of the returning parser.

This makes the expected input of the parser returning this Parsed value optional.

pub fn matches(self) -> Result<bool, E>[src]

Returns whether the current input did match the expected input of the returning parser.

This makes the expected input of the parser returning this Parsed value optional.

pub fn or_parse(self, parse: impl FnOnce() -> Parsed<T, E>) -> Parsed<T, E>[src]

Tries a different parser when the current input did not match the expected input of the returning parser.

This adds another parser to the expected choices for the current input.

This is intentionally not called or_else as calling Result::or_else on an irrecoverably failing parser cannot be used to implement choice, as such a parser can leave the input stream in a modified state when it returns an Err value.

pub fn or_always_parse(
    self,
    parse: impl FnOnce() -> Result<T, E>
) -> Result<T, E>
[src]

Variant of or_parse for when the alternative parser is guaranteed to not fall through.

pub fn and_then<U>(self, parse: impl FnOnce(T) -> Result<U, E>) -> Parsed<U, E>[src]

Locks in the choice when the input matches the expected input of the returning parser.

When the returning parser succeeds, but the passed parser fails, further alternatives will not be tried.

pub fn and_also(
    self,
    parse: impl FnOnce(&mut T) -> Result<(), E>
) -> Parsed<T, E>
[src]

Variant of and_then which always returns the (possibly modified) original value on success.

This is useful to parse delimiters which do not contain any parsed information.

pub fn and_do(self, action: impl FnOnce(&mut T)) -> Parsed<T, E>[src]

Variant of and_also where the action cannot fail.

This is useful to modify a value or to perform side-effects on successful parses.

pub fn map<T2>(self, f: impl FnOnce(T) -> T2) -> Parsed<T2, E>[src]

Replaces a successfully parsed value with the value returned when applying the function f to it.

If the parser was not successful, the error or fallthrough is returned unchanged.

pub fn map_err<E2>(self, f: impl FnOnce(E) -> E2) -> Parsed<T, E2>[src]

Replaces an occured error with the error returned when applying the function f to it.

Trait Implementations

impl<T, E> From<Result<T, E>> for Parsed<T, E>[src]

Auto Trait Implementations

impl<T, E> RefUnwindSafe for Parsed<T, E> where
    E: RefUnwindSafe,
    T: RefUnwindSafe

impl<T, E> Send for Parsed<T, E> where
    E: Send,
    T: Send

impl<T, E> Sync for Parsed<T, E> where
    E: Sync,
    T: Sync

impl<T, E> Unpin for Parsed<T, E> where
    E: Unpin,
    T: Unpin

impl<T, E> UnwindSafe for Parsed<T, E> where
    E: UnwindSafe,
    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, 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.