ixa/
error.rs

1//! Provides `IxaError` and wraps other errors.
2use std::fmt::{self, Debug, Display};
3use std::io;
4
5#[derive(Debug)]
6#[allow(clippy::module_name_repetitions)]
7/// Provides `IxaError` and maps to other errors to
8/// convert to an `IxaError`
9pub enum IxaError {
10    IoError(io::Error),
11    JsonError(serde_json::Error),
12    CsvError(csv::Error),
13    Utf8Error(std::string::FromUtf8Error),
14    ParseIntError(std::num::ParseIntError),
15    IxaError(String),
16}
17
18impl From<io::Error> for IxaError {
19    fn from(error: io::Error) -> Self {
20        IxaError::IoError(error)
21    }
22}
23
24impl From<serde_json::Error> for IxaError {
25    fn from(error: serde_json::Error) -> Self {
26        IxaError::JsonError(error)
27    }
28}
29
30impl From<csv::Error> for IxaError {
31    fn from(error: csv::Error) -> Self {
32        IxaError::CsvError(error)
33    }
34}
35
36impl From<std::string::FromUtf8Error> for IxaError {
37    fn from(error: std::string::FromUtf8Error) -> Self {
38        IxaError::Utf8Error(error)
39    }
40}
41
42impl From<std::num::ParseIntError> for IxaError {
43    fn from(error: std::num::ParseIntError) -> Self {
44        IxaError::ParseIntError(error)
45    }
46}
47
48impl From<String> for IxaError {
49    fn from(error: String) -> Self {
50        IxaError::IxaError(error)
51    }
52}
53
54impl From<&str> for IxaError {
55    fn from(error: &str) -> Self {
56        IxaError::IxaError(error.to_string())
57    }
58}
59
60impl std::error::Error for IxaError {}
61
62impl Display for IxaError {
63    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
64        write!(f, "Error: {self:?}")?;
65        Ok(())
66    }
67}