1use core::fmt;
2use std::error::Error;
3
4#[derive(Debug, Clone, Copy, PartialEq, Eq)]
6pub enum RationalError {
7 ZeroDenominator,
9 DivisionByZero,
11 NormalizationOverflow,
13 ArithmeticOverflow {
15 operation: &'static str,
17 },
18}
19
20impl fmt::Display for RationalError {
21 fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
22 match self {
23 Self::ZeroDenominator => write!(formatter, "denominator must not be zero"),
24 Self::DivisionByZero => write!(formatter, "division by zero-valued rational"),
25 Self::NormalizationOverflow => {
26 write!(
27 formatter,
28 "rational normalization overflowed the current representation"
29 )
30 },
31 Self::ArithmeticOverflow { operation } => {
32 write!(
33 formatter,
34 "rational {operation} overflowed the current representation"
35 )
36 },
37 }
38 }
39}
40
41impl Error for RationalError {}