pub enum ParseFailure<'a> {
Error(ParseError<'a>),
Unrecognized(UnrecognizedToken<'a>),
}
Expand description
Value’s failed parsing result
The parsing process can fail in two different ways:
- The input stream contains invalid tokens: the number, order, or contents of tokens is
incorrect. Such errors are represented by the
ParseError
struct. - The input may be correct, but the current parser does not recognize the input stream’s first
token. In such case, another parser may recognize this token. Such situations arise when
dealing with optional fields, variable number of fields, etc. Such situations are
represented by the
UnexpectedToken
struct.
ParseFailure
enum’s variants encapsulates both these structs.
Variants§
Error(ParseError<'a>)
The parsing failed with an unrecoverable error
Unrecognized(UnrecognizedToken<'a>)
The token is not recognized by the parser
Implementations§
Source§impl<'a> ParseFailure<'a>
impl<'a> ParseFailure<'a>
Sourcepub fn as_error(&self) -> Option<&ParseError<'a>>
pub fn as_error(&self) -> Option<&ParseError<'a>>
Returns a reference to the ParseError
if this ParseFailure
corresponds to an error or
None
otherwise.
Sourcepub fn as_unrecognized(&self) -> Option<&UnrecognizedToken<'a>>
pub fn as_unrecognized(&self) -> Option<&UnrecognizedToken<'a>>
Returns a reference to the UnrecognizedToken
if this ParseFailure
corresponds to a
failure due to an unrecognized token or None
otherwise.
Trait Implementations§
Source§impl<'a> Debug for ParseFailure<'a>
impl<'a> Debug for ParseFailure<'a>
Source§impl<'a, E: Into<ParseError<'a>>> From<E> for ParseFailure<'a>
impl<'a, E: Into<ParseError<'a>>> From<E> for ParseFailure<'a>
Source§impl<'a> From<UnrecognizedToken<'a>> for ParseFailure<'a>
impl<'a> From<UnrecognizedToken<'a>> for ParseFailure<'a>
Source§fn from(unrecognized: UnrecognizedToken<'a>) -> Self
fn from(unrecognized: UnrecognizedToken<'a>) -> Self
Converts to this type from the input type.
Auto Trait Implementations§
impl<'a> Freeze for ParseFailure<'a>
impl<'a> RefUnwindSafe for ParseFailure<'a>
impl<'a> Send for ParseFailure<'a>
impl<'a> Sync for ParseFailure<'a>
impl<'a> Unpin for ParseFailure<'a>
impl<'a> UnwindSafe for ParseFailure<'a>
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
Mutably borrows from an owned value. Read more