Struct ParsingError

Source
pub struct ParsingError<In, Reason = Infallible> {
    pub rest: In,
    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.

To make the error more useful, consider the following options:

Fields§

§rest: In

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<In, Reason> ParsingError<In, Reason>

Source

pub const fn new(rest: In, reason: Reason) -> Self

Create a new fatal parsing error.

Source

pub const fn new_recoverable(rest: In) -> 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, reason: NewReason) -> ParsingError<In, NewReason>

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

Source

pub fn or_reason(self, reason: Reason) -> Self

Makes a recoverable error fatal by giving it a reason, if it’s already fatal, does nothing

Source

pub fn or_reason_if_nonempty(self, reason: Reason) -> Self
where In: Input,

Like ParsingError::or_reason but does nothing if the rest of the input is empty

Source

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

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

Source

pub fn with_src_loc<'path>( self, path: impl PathLike<'path>, input: &str, ) -> FullParsingError<'path, Reason>
where In: Input,

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

Trait Implementations§

Source§

impl<In: Clone, Reason: Clone> Clone for ParsingError<In, Reason>

Source§

fn clone(&self) -> ParsingError<In, 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<In: Debug, Reason: Debug> Debug for ParsingError<In, Reason>

Source§

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

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

impl<In: Input, Reason: Display> Display for ParsingError<In, Reason>

Source§

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

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

impl<In: Input, Reason: Error> Error for ParsingError<In, Reason>

1.30.0 · Source§

fn source(&self) -> Option<&(dyn Error + 'static)>

Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§

fn description(&self) -> &str

👎Deprecated since 1.42.0: use the Display impl or to_string()
1.0.0 · Source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0: replaced by Error::source, which can support downcasting
Source§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type-based access to context intended for error reports. Read more
Source§

impl<In: PartialEq, Reason: PartialEq> PartialEq for ParsingError<In, Reason>

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<In: Copy, Reason: Copy> Copy for ParsingError<In, Reason>

Source§

impl<In: Eq, Reason: Eq> Eq for ParsingError<In, Reason>

Source§

impl<In, Reason> StructuralPartialEq for ParsingError<In, Reason>

Auto Trait Implementations§

§

impl<In, Reason> Freeze for ParsingError<In, Reason>
where In: Freeze, Reason: Freeze,

§

impl<In, Reason> RefUnwindSafe for ParsingError<In, Reason>
where In: RefUnwindSafe, Reason: RefUnwindSafe,

§

impl<In, Reason> Send for ParsingError<In, Reason>
where In: Send, Reason: Send,

§

impl<In, Reason> Sync for ParsingError<In, Reason>
where In: Sync, Reason: Sync,

§

impl<In, Reason> Unpin for ParsingError<In, Reason>
where In: Unpin, Reason: Unpin,

§

impl<In, Reason> UnwindSafe for ParsingError<In, Reason>
where In: UnwindSafe, 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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,

Source§

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
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.