ticker_sniffer/structs/
error.rs

1use std::fmt;
2
3#[derive(Debug)]
4pub enum Error {
5    ParserError(String),
6    TokenFilterError(String),
7    IoError(std::io::Error),
8    Other(String),
9}
10
11impl fmt::Display for Error {
12    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
13        match self {
14            Error::ParserError(msg) => write!(f, "Parser Error: {}", msg),
15            Error::TokenFilterError(msg) => write!(f, "Token Filter Error: {}", msg),
16            Error::IoError(err) => write!(f, "IO Error: {}", err),
17            Error::Other(msg) => write!(f, "Other Error: {}", msg),
18        }
19    }
20}
21
22impl From<String> for Error {
23    fn from(msg: String) -> Error {
24        Error::ParserError(msg)
25    }
26}
27
28impl From<&str> for Error {
29    fn from(msg: &str) -> Error {
30        Error::ParserError(msg.to_string())
31    }
32}
33
34impl From<std::io::Error> for Error {
35    fn from(err: std::io::Error) -> Error {
36        Error::IoError(err)
37    }
38}
39
40impl From<Box<dyn std::error::Error>> for Error {
41    fn from(err: Box<dyn std::error::Error>) -> Error {
42        Error::Other(err.to_string())
43    }
44}