use core::num::IntErrorKind;
#[cfg(displaydoc)]
use displaydoc::Display;
#[cfg_attr(
std,
error("out of range type conversion attempted"),
derive(thiserror::Error)
)]
#[cfg_attr(displaydoc, derive(Display))]
#[derive(Debug, Copy, Clone, Eq, Hash, PartialEq, PartialOrd, Ord)]
pub enum OutOfRangeIntError {
PosOverflow,
NegOverflow,
}
impl From<OutOfRangeIntError> for ParseIntError {
fn from(err: OutOfRangeIntError) -> Self {
ParseIntError::OutOfRange(err)
}
}
#[cfg_attr(std, derive(thiserror::Error))]
#[cfg_attr(displaydoc, derive(Display))]
#[derive(Debug, Copy, Clone, Eq, Hash, PartialEq, PartialOrd, Ord)]
pub enum ParseIntError {
Empty,
InvalidDigit,
OutOfRange(OutOfRangeIntError),
Unknown,
}
impl From<IntErrorKind> for ParseIntError {
fn from(kind: IntErrorKind) -> Self {
match kind {
IntErrorKind::Empty => ParseIntError::Empty,
IntErrorKind::InvalidDigit => ParseIntError::InvalidDigit,
IntErrorKind::NegOverflow => ParseIntError::OutOfRange(OutOfRangeIntError::NegOverflow),
IntErrorKind::PosOverflow => ParseIntError::OutOfRange(OutOfRangeIntError::PosOverflow),
_ => ParseIntError::Unknown,
}
}
}