use chrono::ParseError;
use regex::Error as RegexError;
use serde_json::Error as SerdeError;
use std::{
convert::From, fmt::Display, io::Error as IOError, num::ParseIntError, string::FromUtf8Error,
};
#[derive(Debug, Clone)]
pub struct Alert {
val: String,
}
impl From<ParseError> for Alert {
fn from(value: ParseError) -> Self {
Alert {
val: format!("chrono::ParseError: {}", value),
}
}
}
impl From<RegexError> for Alert {
fn from(value: RegexError) -> Self {
Alert {
val: format!("regex::Error: {}", value),
}
}
}
impl From<IOError> for Alert {
fn from(value: IOError) -> Self {
Alert {
val: format!("io::Error: {}", value),
}
}
}
impl From<ParseIntError> for Alert {
fn from(value: ParseIntError) -> Self {
Alert {
val: format!("num::ParseIntError: {}", value),
}
}
}
impl From<SerdeError> for Alert {
fn from(value: SerdeError) -> Self {
Alert {
val: format!("serde_json::Error: {}", value),
}
}
}
impl From<FromUtf8Error> for Alert {
fn from(value: FromUtf8Error) -> Self {
Alert {
val: format!("string::FromUtf8Error: {}", value),
}
}
}
impl From<&str> for Alert {
fn from(value: &str) -> Self {
Alert {
val: String::from(value),
}
}
}
impl From<String> for Alert {
fn from(value: String) -> Self {
Alert { val: value }
}
}
impl From<&String> for Alert {
fn from(value: &String) -> Self {
Alert { val: value.clone() }
}
}
impl Display for Alert {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
writeln!(f, "{}", self.val)
}
}