use core::fmt::{self, Debug, Display, Formatter};
use core::num::IntErrorKind;
use core::error::Error;
#[derive(PartialEq, Eq, Clone, Debug)]
pub struct ParseIntError {
pub(crate) kind: IntErrorKind,
}
impl Error for ParseIntError {}
impl ParseIntError {
pub const fn kind(&self) -> &IntErrorKind {
&self.kind
}
pub(crate) const fn description(&self) -> &str {
match &self.kind {
IntErrorKind::Empty => "attempt to parse integer from empty string",
IntErrorKind::InvalidDigit => {
"attempt to parse integer from string containing invalid digit"
}
IntErrorKind::PosOverflow => {
"attempt to parse integer too large to be represented by the target type"
}
IntErrorKind::NegOverflow => {
"attempt to parse integer too small to be represented by the target type"
}
IntErrorKind::Zero => {
"attempt to parse the integer `0` which cannot be represented by the target type"
}
_ => panic!("unsupported `IntErrorKind` variant"), }
}
}
impl Display for ParseIntError {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
write!(f, "{} {}", super::err_prefix!(), self.description())
}
}