Enum ParseResult

Source
pub enum ParseResult<'a, TokenKind, T, E> {
    Match {
        value: T,
        remaining: TokenStream<'a, TokenKind>,
    },
    NoMatch,
    Err(E),
}
Expand description

The result of running a parser

Variants§

§

Match

The input matched the parser pattern.

Fields

§value: T

The value produced by the parser

§remaining: TokenStream<'a, TokenKind>

The remaining token stream

§

NoMatch

The input did not match the parser pattern.

§

Err(E)

The input matched the parser pattern but was malformed or invalid.

Implementations§

Source§

impl<'a, TokenKind, T, E> ParseResult<'a, TokenKind, T, E>

Source

pub fn map<U>(self, f: impl FnOnce(T) -> U) -> ParseResult<'a, TokenKind, U, E>

Maps a ParseResult<'a, TokenKind, T, E> to ParseResult<'a, TokenKind, U, E> by applying a function to a contained ParseResult::Match value, leaving an ParseResult::NoMatch and ParseResult::Err value untouched.

Source

pub fn map_err<F>( self, f: impl FnOnce(E) -> F, ) -> ParseResult<'a, TokenKind, T, F>

Maps a ParseResult<'a, TokenKind, T, E> to ParseResult<'a, TokenKind, T, F> by applying a function to a contained ParseResult::Err value, leaving an ParseResult::Match and ParseResult::NoMatch value untouched.

Trait Implementations§

Source§

impl<'a, TokenKind, T, E> FromResidual for ParseResult<'a, TokenKind, T, E>

Source§

fn from_residual(residual: <Self as Try>::Residual) -> Self

🔬This is a nightly-only experimental API. (try_trait_v2)
Constructs the type from a compatible Residual type. Read more
Source§

impl<'a, TokenKind, T, E> Try for ParseResult<'a, TokenKind, T, E>

Source§

type Output = (T, TokenStream<'a, TokenKind>)

🔬This is a nightly-only experimental API. (try_trait_v2)
The type of the value produced by ? when not short-circuiting.
Source§

type Residual = ParseResult<'a, TokenKind, Infallible, E>

🔬This is a nightly-only experimental API. (try_trait_v2)
The type of the value passed to FromResidual::from_residual as part of ? when short-circuiting. Read more
Source§

fn from_output((value, remaining): Self::Output) -> Self

🔬This is a nightly-only experimental API. (try_trait_v2)
Constructs the type from its Output type. Read more
Source§

fn branch(self) -> ControlFlow<Self::Residual, Self::Output>

🔬This is a nightly-only experimental API. (try_trait_v2)
Used in ? to decide whether the operator should produce a value (because this returned ControlFlow::Continue) or propagate a value back to the caller (because this returned ControlFlow::Break). Read more

Auto Trait Implementations§

§

impl<'a, TokenKind, T, E> Freeze for ParseResult<'a, TokenKind, T, E>
where T: Freeze, E: Freeze,

§

impl<'a, TokenKind, T, E> RefUnwindSafe for ParseResult<'a, TokenKind, T, E>
where T: RefUnwindSafe, E: RefUnwindSafe, TokenKind: RefUnwindSafe,

§

impl<'a, TokenKind, T, E> Send for ParseResult<'a, TokenKind, T, E>
where T: Send, E: Send, TokenKind: Sync,

§

impl<'a, TokenKind, T, E> Sync for ParseResult<'a, TokenKind, T, E>
where T: Sync, E: Sync, TokenKind: Sync,

§

impl<'a, TokenKind, T, E> Unpin for ParseResult<'a, TokenKind, T, E>
where T: Unpin, E: Unpin,

§

impl<'a, TokenKind, T, E> UnwindSafe for ParseResult<'a, TokenKind, T, E>
where T: UnwindSafe, E: UnwindSafe, TokenKind: RefUnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.