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:
ParsingError::with_src_loc- [
Parser::with_full_error]
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 adapt_reason<NewReason>(self) -> ParsingError<In, NewReason>where
Infallible: From<Reason>,
pub fn adapt_reason<NewReason>(self) -> ParsingError<In, NewReason>where
Infallible: From<Reason>,
Convert the reason of an always recoverable error to another type. This will be a no-op since it’s statically guaranteed that the reason doesn’t exist.
Sourcepub fn with_src_loc<'a>(
self,
path: impl PathLike<'a>,
src: &'a str,
) -> FullParsingError<'a, Reason>where
In: Input,
pub fn with_src_loc<'a>(
self,
path: impl PathLike<'a>,
src: &'a str,
) -> FullParsingError<'a, Reason>where
In: Input,
Turns the error into a FullParsingError for a more informative report.
The error will point to the provided source code. The provided path will only be used for display purposes, this method won’t access the file system.
Sourcepub fn with_file_loc<'a>(
self,
path: impl PathLike<'a>,
) -> Result<FullParsingError<'a, Reason>>where
In: Input,
Available on crate feature std only.
pub fn with_file_loc<'a>(
self,
path: impl PathLike<'a>,
) -> Result<FullParsingError<'a, Reason>>where
In: Input,
std only.Turns this error into a FullParsingError that points to a file on the machine, for a more informative report.
§Errors
Returns an error if std::fs::read_to_string does.
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 moreSource§impl<In: Input, Reason: Error> Error for ParsingError<In, Reason>
impl<In: Input, Reason: Error> Error for ParsingError<In, Reason>
1.30.0 · Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
impl<In: Copy, Reason: Copy> Copy for ParsingError<In, Reason>
impl<In: Eq, Reason: Eq> Eq for ParsingError<In, Reason>
impl<In, Reason> StructuralPartialEq for ParsingError<In, Reason>
Auto Trait Implementations§
impl<In, Reason> Freeze for ParsingError<In, Reason>
impl<In, Reason> RefUnwindSafe for ParsingError<In, Reason>where
In: RefUnwindSafe,
Reason: RefUnwindSafe,
impl<In, Reason> Send for ParsingError<In, Reason>
impl<In, Reason> Sync for ParsingError<In, Reason>
impl<In, Reason> Unpin for ParsingError<In, Reason>
impl<In, Reason> UnwindSafe for ParsingError<In, Reason>where
In: UnwindSafe,
Reason: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more