use crate::Sign;
#[doc = crate::TAG_NUM!()]
#[doc = crate::TAG_RESULT!()]
pub type NumResult<T> = crate::Result<T, NumError>;
#[doc = crate::TAG_NUM!()]
#[doc = crate::TAG_ERROR_COMPOSITE!()]
#[non_exhaustive]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub enum NumError {
NotImplemented,
NotSupported,
Unspecified,
Invalid,
NoInverse,
MismatchedSizes,
IncompatibleBounds,
NonNegativeRequired,
PositiveRequired,
NonZeroRequired,
Overflow(Option<Sign>),
}
#[allow(dead_code)]
impl NumError {
pub(crate) const fn ni<T>() -> NumResult<T> {
Err(NumError::NotImplemented)
}
pub(crate) const fn ns<T>() -> NumResult<T> {
Err(NumError::NotSupported)
}
}
mod core_impls {
use crate::{Display, FmtResult, Formatter, NumError, Sign};
impl crate::Error for NumError {}
impl crate::ExtError for NumError {
type Kind = ();
fn error_eq(&self, other: &Self) -> bool {
self == other
}
fn error_kind(&self) -> Self::Kind {}
}
impl Display for NumError {
fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult<()> {
use NumError as E;
match self {
E::NotImplemented => write!(f, "Not implemented."),
E::NotSupported => write!(f, "Not supported."),
E::Unspecified => write!(f, "Unspecified."),
E::Invalid => write!(f, "Invalid value."),
E::NoInverse => write!(f, "An inverse doesn't exist."),
E::IncompatibleBounds => {
write!(f, "The given bounds are incompatible.")
}
E::MismatchedSizes => {
write!(f, "The provided values are not compatible in size.")
}
E::NonNegativeRequired => write!(f, "A non-negative value is required."),
E::PositiveRequired => write!(f, "A positive value is required.."),
E::NonZeroRequired => write!(f, "A non-zero value is required."),
E::Overflow(sign) => {
if let Some(sign) = sign {
match sign {
Sign::Positive => write!(f, "Positive overflow."),
Sign::Negative => write!(f, "Negative overflow."),
Sign::None => write!(f, "Unsigned overflow."), }
} else {
write!(f, "Overflow.")
}
}
}
}
}
}