iadb_api/
error.rs

1// Error types
2use std::error::Error as ErrorTrait;
3use reqwest::Error as ReqwestError;
4use csv::Error as CSVError;
5// Dependencies
6use std::{fmt::Display, convert::From};
7
8
9#[derive(Debug)]
10pub enum Error {
11    // Reqwest errors
12    ReqwestError(ReqwestError),
13    // CSV errors
14    CSVError(CSVError),
15}
16
17impl Display for Error {
18    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
19        match self {
20            // Reqwest errors
21            Error::ReqwestError(e) => write!(f, "Reqwest Error: {}", e.to_string()),
22            // CSV errors
23            Error::CSVError(e) => write!(f, "CSV Error: {}", e.to_string()),
24        }
25    }
26}
27
28impl ErrorTrait for Error {}
29
30impl From<ReqwestError> for Error {
31    fn from(value: ReqwestError) -> Self {
32        Error::ReqwestError(value)
33    }
34}
35
36impl From<CSVError> for Error {
37    fn from(value: CSVError) -> Self {
38        Error::CSVError(value)
39    }
40}