summary refs log tree commit diff
path: root/lib/src/error.rs
blob: 216df78495a0fd546bed932ad68b9d1bd080b3eb (plain)
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
#[derive(Debug)]
pub enum Error {
  IO(std::io::Error),
  Parse,
}

impl std::error::Error for Error { }

impl std::fmt::Display for Error {
  fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
    match self {
      Error::IO(e) => e.fmt(f),
      Error::Parse => f.write_str("Parse error"),
    }
  }
}

impl std::cmp::PartialEq for Error {
  fn eq(&self, other: &Self) -> bool {
    match (self, other) {
      (Error::IO(_), Error::IO(_)) =>
        false,
      (Error::Parse, Error::Parse) =>
        true,
      _ =>
        false,
    }
  }
}

impl From<std::io::Error> for Error {
  fn from(e: std::io::Error) -> Error {
    Error::IO(e)
  }
}

impl From<std::num::ParseIntError> for Error {
  fn from(_: std::num::ParseIntError) -> Error {
    Error::Parse
  }
}