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
use std::error;
use std::fmt;
#[derive(Debug, PartialEq, Clone, Copy)]
pub enum SpError {
UnknownEnumVariant,
NotEnoughSpace,
CountFieldOverflow,
InvalidBytes,
BadAlignment,
}
impl fmt::Display for SpError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
SpError::UnknownEnumVariant => write!(f, "Encountered invalid enum variant ID"),
SpError::NotEnoughSpace => {
write!(f, "Not enough bytes in the buffer to parse wanted type")
}
SpError::CountFieldOverflow => write!(
f,
"The count field's type is too small for the number of items !"
),
SpError::InvalidBytes => write!(f, "Failed to parse the bytes into the wanted type"),
SpError::BadAlignment => write!(f, "Input bytes are misaligned"),
}
}
}
impl error::Error for SpError {
fn cause(&self) -> Option<&dyn error::Error> {
Some(self)
}
}