75 lines
2.0 KiB
Rust
75 lines
2.0 KiB
Rust
use std::num::{ParseFloatError, ParseIntError};
|
|
use std::str::ParseBoolError;
|
|
|
|
#[derive(Debug)]
|
|
pub enum ParseError {
|
|
AttrMissing,
|
|
ParseIntErr(ParseIntError),
|
|
ParseFloatErr(ParseFloatError),
|
|
ParseBoolErr(ParseBoolError),
|
|
ParseChronoErr(chrono::ParseError),
|
|
}
|
|
|
|
impl From<ParseIntError> for ParseError {
|
|
fn from(error: ParseIntError) -> Self {
|
|
ParseError::ParseIntErr(error)
|
|
}
|
|
}
|
|
|
|
impl From<ParseFloatError> for ParseError {
|
|
fn from(error: ParseFloatError) -> Self {
|
|
ParseError::ParseFloatErr(error)
|
|
}
|
|
}
|
|
|
|
impl From<ParseBoolError> for ParseError {
|
|
fn from(error: ParseBoolError) -> Self {
|
|
ParseError::ParseBoolErr(error)
|
|
}
|
|
}
|
|
|
|
impl From<chrono::ParseError> for ParseError {
|
|
fn from(error: chrono::ParseError) -> Self {
|
|
ParseError::ParseChronoErr(error)
|
|
}
|
|
}
|
|
|
|
impl std::fmt::Display for ParseError {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
match self {
|
|
ParseError::AttrMissing => write!(f, "Attr missing"),
|
|
ParseError::ParseIntErr(e) => write!(f, "Int parse error: {}", e),
|
|
ParseError::ParseFloatErr(e) => write!(f, "Int parse error: {}", e),
|
|
ParseError::ParseBoolErr(e) => write!(f, "Bool parse error: {}", e),
|
|
ParseError::ParseChronoErr(e) => write!(f, "Chrono parse error: {}", e),
|
|
}
|
|
}
|
|
}
|
|
|
|
#[derive(Debug)]
|
|
pub enum DSNError {
|
|
ParseErr(ParseError),
|
|
ReqwestErr(reqwest::Error),
|
|
}
|
|
|
|
impl From<ParseError> for DSNError {
|
|
fn from(err: ParseError) -> Self {
|
|
DSNError::ParseErr(err)
|
|
}
|
|
}
|
|
|
|
impl From<reqwest::Error> for DSNError {
|
|
fn from(err: reqwest::Error) -> Self {
|
|
DSNError::ReqwestErr(err)
|
|
}
|
|
}
|
|
|
|
impl std::fmt::Display for DSNError {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
match self {
|
|
DSNError::ParseErr(e) => write!(f, "Req Parse Error: {}", e),
|
|
DSNError::ReqwestErr(e) => write!(f, "Reqwest Error: {}", e),
|
|
}
|
|
}
|
|
}
|