1use core::fmt::{Display, Formatter};
10
11#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
13pub enum ArithmeticError {
14 Undefined,
15 Underflow,
16 Overflow,
17}
18
19impl ArithmeticError {
20 fn brief(self) -> &'static str {
21 match self {
22 ArithmeticError::Undefined => Undefined::BRIEF,
23 ArithmeticError::Underflow => Underflow::BRIEF,
24 ArithmeticError::Overflow => Overflow::BRIEF,
25 }
26 }
27}
28
29impl Display for ArithmeticError {
30 fn fmt(&self, f: &mut Formatter) -> core::fmt::Result {
31 f.write_str(self.brief())
32 }
33}
34
35#[cfg(feature = "std")]
36impl std::error::Error for ArithmeticError {
37 fn description(&self) -> &str { self.brief() }
38}
39
40#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
43pub struct Overflow;
44
45impl Overflow {
46 const BRIEF: &'static str = "arithmetic overflow";
47}
48
49impl Display for Overflow {
50 fn fmt(&self, f: &mut Formatter) -> core::fmt::Result {
51 f.write_str(Overflow::BRIEF)
52 }
53}
54
55#[cfg(feature = "std")]
56impl std::error::Error for Overflow {
57 fn description(&self) -> &str { Overflow::BRIEF }
58}
59
60#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
63pub enum RangeError {
64 Underflow,
65 Overflow,
66}
67
68impl RangeError {
69 fn brief(self) -> &'static str {
70 match self {
71 RangeError::Underflow => Underflow::BRIEF,
72 RangeError::Overflow => Overflow::BRIEF,
73 }
74 }
75}
76
77impl Display for RangeError {
78 fn fmt(&self, f: &mut Formatter) -> core::fmt::Result {
79 f.write_str(self.brief())
80 }
81}
82
83#[cfg(feature = "std")]
84impl std::error::Error for RangeError {
85 fn description(&self) -> &str { self.brief() }
86}
87
88#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
91pub struct Undefined;
92
93impl Undefined {
94 const BRIEF: &'static str = "arithmetic result undefined";
95}
96
97impl Display for Undefined {
98 fn fmt(&self, f: &mut Formatter) -> core::fmt::Result {
99 f.write_str(Undefined::BRIEF)
100 }
101}
102
103#[cfg(feature = "std")]
104impl std::error::Error for Undefined {
105 fn description(&self) -> &str { Undefined::BRIEF }
106}
107
108#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
111pub struct Underflow;
112
113impl Underflow {
114 const BRIEF: &'static str = "arithmetic underflow";
115}
116
117impl Display for Underflow {
118 fn fmt(&self, f: &mut Formatter) -> core::fmt::Result {
119 f.write_str(Underflow::BRIEF)
120 }
121}
122
123#[cfg(feature = "std")]
124impl std::error::Error for Underflow {
125 fn description(&self) -> &str { Underflow::BRIEF }
126}