use std::string::FromUtf8Error; use std::time::SystemTimeError; use std::{fmt, io, num}; use tokio::sync::mpsc::error::SendError; use url::ParseError; #[derive(Debug, Clone, PartialEq)] pub struct Error { message: String, } impl fmt::Display for Error { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> { write!(f, "{}", self.message) } } impl std::error::Error for Error { fn description(&self) -> &str { &self.message } } // Implement std::convert::From for AppError; from io::Error impl From for Error { fn from(error: io::Error) -> Self { Error { message: error.to_string(), } } } impl From for Error { fn from(error: num::ParseIntError) -> Self { Error { message: error.to_string(), } } } impl From for Error { fn from(error: ParseError) -> Self { Error { message: error.to_string(), } } } impl From for Error { fn from(error: FromUtf8Error) -> Self { Error { message: error.to_string(), } } } impl From for Error { fn from(error: SystemTimeError) -> Self { Error { message: error.to_string(), } } } impl From for Error { fn from(error: SendError) -> Self { Error { message: error.to_string(), } } } impl Error { pub fn new(message: String) -> Self { Error { message } } }