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: InThe 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>
impl<In, Reason> ParsingError<In, Reason>
Sourcepub const fn new_recoverable(rest: In) -> Self
pub const fn new_recoverable(rest: In) -> Self
Create a new recoverable parsing error.
Sourcepub const fn is_recoverable(&self) -> bool
pub const fn is_recoverable(&self) -> bool
Returns a boolean indicating whether the error is recoverable.
Sourcepub fn reason<NewReason>(self, reason: NewReason) -> ParsingError<In, NewReason>
pub fn reason<NewReason>(self, reason: NewReason) -> ParsingError<In, NewReason>
Changes the reason associated with the error, making the error fatal.
Sourcepub fn or_reason(self, reason: Reason) -> Self
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
Sourcepub fn or_reason_if_nonempty(self, reason: Reason) -> Selfwhere
In: Input,
pub fn or_reason_if_nonempty(self, reason: Reason) -> Selfwhere
In: Input,
Like ParsingError::or_reason but does nothing if the rest of the input is empty
Sourcepub fn map_reason<NewReason>(
self,
f: impl FnOnce(Reason) -> NewReason,
) -> ParsingError<In, NewReason>
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.
Sourcepub fn with_src_loc<'path>(
self,
path: impl PathLike<'path>,
input: &str,
) -> FullParsingError<'path, Reason>where
In: Input,
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>
impl<In: Clone, Reason: Clone> Clone for ParsingError<In, Reason>
Source§fn clone(&self) -> ParsingError<In, Reason>
fn clone(&self) -> ParsingError<In, Reason>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more