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