Struct shrimple_parser::ParsingError

source ·
pub struct ParsingError<'rest, Reason> {
    pub rest: &'rest str,
    pub reason: Option<Reason>,
}
Expand description

Error returned by a parser.

A parsing error may be either recoverable or fatal, parser methods such as Parser::or allow trying different paths if a recoverable error occurs, whereas a fatal error is not intended to be recovered from and should just be propagated.

This error isn’t an error per Rust’s definition, it doesn’t implement std::error::Error, the reason being that it lacks any information that’d make it actually useful, to make the error more useful, consider the following options:

Fields§

§rest: &'rest str

The rest of the input that could not be processed.

§reason: Option<Reason>

What the parser expected, the reason for the error. None means that the error is recoverable.

Implementations§

source§

impl<'rest, Reason> ParsingError<'rest, Reason>

source

pub const fn new(rest: &'rest str, expected: Reason) -> Self

Create a new fatal parsing error.

source

pub const fn new_recoverable(rest: &'rest str) -> Self

Create a new recoverable parsing error.

source

pub const fn is_recoverable(&self) -> bool

Returns a boolean indicating whether the error is recoverable.

source

pub fn reason<NewReason>( self, expected: NewReason ) -> ParsingError<'rest, NewReason>

Changes the reason associated with the error, making the error fatal.

source

pub fn map_reason<NewReason>( self, f: impl FnOnce(Reason) -> NewReason ) -> ParsingError<'rest, NewReason>

Transforms the reason by calling f, except if it’s a recoverable error, in which case it remains recoverable.

source

pub fn narrow_reason<NewReason>( self, expected: NewReason ) -> ParsingError<'rest, NewReason>

Changes the reason associated with error, except if it’s a recoverable error, in which case it remains recoverable.

source

pub fn with_src_loc<'path>( self, path: &'path Path, src: &str ) -> FullParsingError<'path, Reason>

Turns this error into a FullParsingError for more informative error report.

Trait Implementations§

source§

impl<'rest, Reason: Clone> Clone for ParsingError<'rest, Reason>

source§

fn clone(&self) -> ParsingError<'rest, Reason>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<'rest, Reason: Debug> Debug for ParsingError<'rest, Reason>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<'rest, Reason: PartialEq> PartialEq for ParsingError<'rest, Reason>

source§

fn eq(&self, other: &ParsingError<'rest, Reason>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<'rest, Reason: Copy> Copy for ParsingError<'rest, Reason>

source§

impl<'rest, Reason: Eq> Eq for ParsingError<'rest, Reason>

source§

impl<'rest, Reason> StructuralPartialEq for ParsingError<'rest, Reason>

Auto Trait Implementations§

§

impl<'rest, Reason> Freeze for ParsingError<'rest, Reason>
where Reason: Freeze,

§

impl<'rest, Reason> RefUnwindSafe for ParsingError<'rest, Reason>
where Reason: RefUnwindSafe,

§

impl<'rest, Reason> Send for ParsingError<'rest, Reason>
where Reason: Send,

§

impl<'rest, Reason> Sync for ParsingError<'rest, Reason>
where Reason: Sync,

§

impl<'rest, Reason> Unpin for ParsingError<'rest, Reason>
where Reason: Unpin,

§

impl<'rest, Reason> UnwindSafe for ParsingError<'rest, Reason>
where Reason: UnwindSafe,

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> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

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

§

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>,

§

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.