1use crate::table;
2
3#[derive(Debug)]
4pub enum Error {
5 Parse(ParseError),
6 IO(std::io::Error),
7 Utf8(std::str::Utf8Error),
8}
9
10impl std::fmt::Display for Error {
11 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
12 match self {
13 Error::Parse(err) => write!(f, "{}", err),
14 Error::IO(err) => write!(f, "{:?}", err),
15 Error::Utf8(err) => write!(f, "{}", err),
16 }
17 }
18}
19
20impl std::error::Error for Error {}
21
22impl From<ParseError> for Error {
23 fn from(err: ParseError) -> Self {
24 Error::Parse(err)
25 }
26}
27
28impl From<std::io::Error> for Error {
29 fn from(err: std::io::Error) -> Self {
30 Error::IO(err)
31 }
32}
33
34impl From<std::str::Utf8Error> for Error {
35 fn from(err: std::str::Utf8Error) -> Self {
36 Error::Utf8(err)
37 }
38}
39
40#[derive(Debug, PartialEq)]
41pub struct ParseError {
42 pub state: table::State,
43 pub byte: u8,
44}
45
46impl std::fmt::Display for ParseError {
47 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
48 write!(
49 f,
50 "parse error with byte {:X} in state {:?}",
51 self.byte, self.state
52 )
53 }
54}
55
56impl std::error::Error for ParseError {}