use core::fmt::Display;
#[derive(Debug, Clone)]
#[non_exhaustive]
pub enum Error {
InvalidInput {
from: usize,
to: usize,
description: &'static str,
},
Extra { from: usize },
InvalidPosition,
}
impl Display for Error {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match *self {
Error::InvalidInput {
from,
to,
description,
} => write!(
f,
"Invalid input: failed to parse s[{}..{}]: {}",
from, to, description,
),
Error::Extra { from } => write!(f, "Extra input: s[{}..] was left unread", from),
Error::InvalidPosition => f.write_str("Invalid position"),
}
}
}
#[cfg(feature = "std")]
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
impl std::error::Error for Error {}
pub type Result<T> = core::result::Result<T, Error>;