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