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 strThe 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>
impl<'rest, Reason> ParsingError<'rest, Reason>
sourcepub const fn new_recoverable(rest: &'rest str) -> Self
pub const fn new_recoverable(rest: &'rest str) -> 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,
expected: NewReason
) -> ParsingError<'rest, NewReason>
pub fn reason<NewReason>( self, expected: NewReason ) -> ParsingError<'rest, NewReason>
Changes the reason associated with the error, making the error fatal.
sourcepub fn map_reason<NewReason>(
self,
f: impl FnOnce(Reason) -> NewReason
) -> ParsingError<'rest, NewReason>
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.
sourcepub fn narrow_reason<NewReason>(
self,
expected: NewReason
) -> ParsingError<'rest, NewReason>
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.
sourcepub fn with_src_loc<'path>(
self,
path: &'path Path,
src: &str
) -> FullParsingError<'path, Reason>
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>
impl<'rest, Reason: Clone> Clone for ParsingError<'rest, Reason>
source§fn clone(&self) -> ParsingError<'rest, Reason>
fn clone(&self) -> ParsingError<'rest, Reason>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moresource§impl<'rest, Reason: Debug> Debug for ParsingError<'rest, Reason>
impl<'rest, Reason: Debug> Debug for ParsingError<'rest, Reason>
source§impl<'rest, Reason: PartialEq> PartialEq for ParsingError<'rest, Reason>
impl<'rest, Reason: PartialEq> PartialEq for ParsingError<'rest, Reason>
source§fn eq(&self, other: &ParsingError<'rest, Reason>) -> bool
fn eq(&self, other: &ParsingError<'rest, Reason>) -> bool
self and other values to be equal, and is used
by ==.