use std::error;
use std::fmt;
/// The error type for parsers and their combinators
///
/// This crate takes a straightforward approach to handling errors:
///
/// All built-in parsers and combinators return [Error::Mismatch](crate::result::Error::Mismatch)
///
/// The crate consumer may define parsers that return different errors by using the
/// [Custom](crate::result::Error::Custom) variant
#[derive(Debug)]
pub enum Error<E> {
/// The parser failed to recognized the input
Mismatch,
/// The parser failed with a user provided error
Custom(E),
}
impl<E: error::Error> error::Error for Error<E> {}
impl<E: error::Error> fmt::Display for Error<E> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Error::Mismatch => write!(f, "parser failed to match"),
Error::Custom(inner) => fmt::Display::fmt(inner, f),
}
}
}
/// The return value of this crate's parsers
pub type Res<In, Out, E> = Result<(Out, In), Error<E>>;