use std::{convert::Infallible, error, fmt, num::TryFromIntError};
use num::bigint::TryFromBigIntError;
pub type AdicResult<A> = Result<A, AdicError>;
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum AdicError {
AdicIntegerExpected,
BadConversion,
BadDigit,
DivideByPrime,
DivideByZero,
InfiniteOperation,
IllDefined(String),
InappropriatePrecision(String),
MixedCharacteristic,
NoPrimeSet,
TryFromIntError,
Severe(String),
}
impl fmt::Display for AdicError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{self:?}")
}
}
impl error::Error for AdicError { }
impl From<TryFromIntError> for AdicError {
fn from(_: TryFromIntError) -> Self {
AdicError::TryFromIntError
}
}
impl<BI> From<TryFromBigIntError<BI>> for AdicError {
fn from(_: TryFromBigIntError<BI>) -> Self {
AdicError::TryFromIntError
}
}
impl From<Infallible> for AdicError {
fn from(_: Infallible) -> Self {
panic!("Infallible error; catastrophic")
}
}