use core::fmt::{Debug, Display, Formatter};
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum DecimalError {
MaxNFracDigitsExceeded,
InternalOverflow,
InfiniteValue,
NotANumber,
DivisionByZero,
}
impl DecimalError {
#[doc(hidden)]
#[must_use]
pub const fn _description(&self) -> &str {
match self {
Self::MaxNFracDigitsExceeded => {
"More than MAX_N_FRAC_DIGITS fractional decimal digits \
requested."
}
Self::InternalOverflow => "Internal representation exceeded.",
Self::InfiniteValue => "Can't convert infinite value to Decimal.",
Self::NotANumber => "Given value is not a number.",
Self::DivisionByZero => "Division by Zero.",
}
}
}
impl Display for DecimalError {
fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
Display::fmt(self._description(), f)
}
}
#[cfg(feature = "std")]
impl std::error::Error for DecimalError {}