1#[derive(Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Hash, Debug)]
23pub struct OverflowError<T = usize> {
25 pub max: T,
27 pub value: T,
29}
30
31impl core::fmt::Display for OverflowError {
32 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
33 write!(
34 f,
35 "Unable to construct bit-sized integer from a value `{}` overflowing max value `{}`",
36 self.value, self.max
37 )
38 }
39}
40
41#[cfg(feature = "std")]
42impl std::error::Error for OverflowError {}
43
44#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
45pub enum DivError {
46 ZeroDiv,
47 Overflow,
48}
49
50impl core::fmt::Display for DivError {
51 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
52 match *self {
53 DivError::ZeroDiv => write!(f, "division by zero"),
54 DivError::Overflow => write!(f, "division with overflow"),
55 }
56 }
57}
58
59#[cfg(feature = "std")]
60impl std::error::Error for DivError {}
61
62#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
63pub enum PositDecodeError {
64 Zero,
65 NaR,
66}
67
68impl core::fmt::Display for PositDecodeError {
69 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
70 match *self {
71 PositDecodeError::Zero => write!(f, "exception value zero"),
72 PositDecodeError::NaR => write!(f, "exception value NaR"),
73 }
74 }
75}
76
77#[cfg(feature = "std")]
78impl std::error::Error for PositDecodeError {}
79
80#[derive(Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Hash, Debug)]
81pub struct ParseLengthError {
83 pub actual: usize,
85 pub expected: usize,
87}
88
89impl core::fmt::Display for ParseLengthError {
90 fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
91 write!(f, "Invalid length: got {}, expected {}", self.actual, self.expected)
92 }
93}
94#[cfg(feature = "std")]
95impl std::error::Error for ParseLengthError {}