Trait ParserError

Source
pub trait ParserError<I: Stream>: Sized {
    type Inner;

    // Required methods
    fn from_input(input: &I) -> Self;
    fn into_inner(self) -> Result<Self::Inner, Self>;

    // Provided methods
    fn assert(input: &I, _message: &'static str) -> Self
       where I: Debug { ... }
    fn incomplete(input: &I, _needed: Needed) -> Self { ... }
    fn append(
        self,
        _input: &I,
        _token_start: &<I as Stream>::Checkpoint,
    ) -> Self { ... }
    fn or(self, other: Self) -> Self { ... }
    fn is_backtrack(&self) -> bool { ... }
    fn is_incomplete(&self) -> bool { ... }
    fn needed(&self) -> Option<Needed> { ... }
}
Expand description

The basic Parser trait for errors

It provides methods to create an error from some combinators, and combine existing errors in combinators like alt.

Required Associated Types§

Source

type Inner

Generally, Self

Mostly used for ErrMode

Required Methods§

Source

fn from_input(input: &I) -> Self

Creates an error from the input position

Source

fn into_inner(self) -> Result<Self::Inner, Self>

Unwrap the mode, returning the underlying error, if present

Provided Methods§

Source

fn assert(input: &I, _message: &'static str) -> Self
where I: Debug,

Process a parser assertion

Source

fn incomplete(input: &I, _needed: Needed) -> Self

There was not enough data to determine the appropriate action

More data needs to be buffered before retrying the parse.

This must only be set when the Stream is partial, like with Partial

Convert this into an Backtrack with Parser::complete_err

Source

fn append(self, _input: &I, _token_start: &<I as Stream>::Checkpoint) -> Self

Like ParserError::from_input but merges it with the existing error.

This is useful when backtracking through a parse tree, accumulating error context on the way.

Source

fn or(self, other: Self) -> Self

Combines errors from two different parse branches.

For example, this would be used by alt to report the error from each case.

Source

fn is_backtrack(&self) -> bool

Is backtracking and trying new parse branches allowed?

Source

fn is_incomplete(&self) -> bool

Is more data Needed

This must be the same as err.needed().is_some()

Source

fn needed(&self) -> Option<Needed>

Extract the Needed data, if present

Self::needed().is_some() must be the same as err.is_incomplete()

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl<I: Stream> ParserError<I> for ()

Source§

type Inner = ()

Source§

fn from_input(_: &I) -> Self

Source§

fn into_inner(self) -> Result<Self::Inner, Self>

Implementors§

Source§

impl<I, C> ParserError<I> for TreeError<I, C>
where I: Stream + Clone,

Available on crate feature std only.
Source§

impl<I: Stream + Clone> ParserError<I> for InputError<I>

Source§

impl<I: Stream> ParserError<I> for EmptyError

Source§

impl<I: Stream, C> ParserError<I> for ContextError<C>

Source§

impl<I: Stream, E: ParserError<I>> ParserError<I> for ErrMode<E>

Source§

type Inner = E