use core::fmt::{Display, Formatter};
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
pub enum ArithmeticError {
Undefined,
Underflow,
Overflow,
}
impl ArithmeticError {
fn brief(self) -> &'static str {
match self {
ArithmeticError::Undefined => Undefined::BRIEF,
ArithmeticError::Underflow => Underflow::BRIEF,
ArithmeticError::Overflow => Overflow::BRIEF,
}
}
}
impl Display for ArithmeticError {
fn fmt(&self, f: &mut Formatter) -> core::fmt::Result {
f.write_str(self.brief())
}
}
#[cfg(feature = "std")]
impl std::error::Error for ArithmeticError {
fn description(&self) -> &str { self.brief() }
}
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
pub struct Overflow;
impl Overflow {
const BRIEF: &'static str = "arithmetic overflow";
}
impl Display for Overflow {
fn fmt(&self, f: &mut Formatter) -> core::fmt::Result {
f.write_str(Overflow::BRIEF)
}
}
#[cfg(feature = "std")]
impl std::error::Error for Overflow {
fn description(&self) -> &str { Overflow::BRIEF }
}
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
pub enum RangeError {
Underflow,
Overflow,
}
impl RangeError {
fn brief(self) -> &'static str {
match self {
RangeError::Underflow => Underflow::BRIEF,
RangeError::Overflow => Overflow::BRIEF,
}
}
}
impl Display for RangeError {
fn fmt(&self, f: &mut Formatter) -> core::fmt::Result {
f.write_str(self.brief())
}
}
#[cfg(feature = "std")]
impl std::error::Error for RangeError {
fn description(&self) -> &str { self.brief() }
}
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
pub struct Undefined;
impl Undefined {
const BRIEF: &'static str = "arithmetic result undefined";
}
impl Display for Undefined {
fn fmt(&self, f: &mut Formatter) -> core::fmt::Result {
f.write_str(Undefined::BRIEF)
}
}
#[cfg(feature = "std")]
impl std::error::Error for Undefined {
fn description(&self) -> &str { Undefined::BRIEF }
}
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
pub struct Underflow;
impl Underflow {
const BRIEF: &'static str = "arithmetic underflow";
}
impl Display for Underflow {
fn fmt(&self, f: &mut Formatter) -> core::fmt::Result {
f.write_str(Underflow::BRIEF)
}
}
#[cfg(feature = "std")]
impl std::error::Error for Underflow {
fn description(&self) -> &str { Underflow::BRIEF }
}