1use std::error;
2use std::fmt;
3
4
5#[derive(Debug, Clone)]
6pub enum ParserError {
7 InvalidOpcode(u8),
8 NotEnoughBytes(usize),
9}
10
11impl fmt::Display for ParserError {
12 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
13 match *self {
14 Self::InvalidOpcode(op) =>
15 write!(f, "invalid opcode: {:#X}", op),
16 Self::NotEnoughBytes(len) =>
17 write!(f, "not enough bytes to be parsed ({} bytes)", len),
18 }
19 }
20}
21
22impl error::Error for ParserError {
23 fn source(&self) -> Option<&(dyn error::Error + 'static)> {
24 match *self {
25 Self::InvalidOpcode(_) => None,
26 Self::NotEnoughBytes(_) => None,
27 }
28 }
29}