use { crate::prelude::{ParseRequestError, ParseResponseError}, std::{fmt, io}, }; #[derive(Debug)] /// Errors which might occur when sending a message pub enum Error { DnsError, TlsError(rustls::Error), RequestError(ParseRequestError), ResponseError(ParseResponseError), IoError(io::Error), } impl fmt::Display for Error { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { Self::DnsError => write!(f, "Dns Error"), Self::TlsError(e) => write!(f, "{e}"), Self::RequestError(e) => write!(f, "{e}"), Self::ResponseError(e) => write!(f, "{e}"), Self::IoError(e) => write!(f, "{e}"), } } } impl std::error::Error for Error { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { match self { Self::DnsError => None, Self::RequestError(e) => Some(e), Self::ResponseError(e) => Some(e), Self::TlsError(e) => Some(e), Self::IoError(e) => Some(e), } } } impl From for Error { fn from(value: rustls::Error) -> Self { Self::TlsError(value) } } impl From for Error { fn from(value: ParseRequestError) -> Self { Self::RequestError(value) } } impl From for Error { fn from(value: ParseResponseError) -> Self { Self::ResponseError(value) } } impl From for Error { fn from(value: io::Error) -> Self { Self::IoError(value) } }