From 434ede72159b5f9ea588b9ee8c361a3247aa2f35 Mon Sep 17 00:00:00 2001 From: Mauro D Date: Mon, 22 May 2023 13:07:29 +0000 Subject: [PATCH] Added Display to Error --- src/lib.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 0c1246c..da8a2c2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -320,3 +320,23 @@ impl AsRef> for EhloResponse { self } } + +impl Display for Error { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + Error::NeedsMoreData { bytes_left } => { + write!(f, "Needs more data: {} bytes left", bytes_left) + } + Error::UnknownCommand => write!(f, "Unknown command"), + Error::InvalidSenderAddress => write!(f, "Invalid sender address"), + Error::InvalidRecipientAddress => write!(f, "Invalid recipient address"), + Error::SyntaxError { syntax } => write!(f, "Syntax error: {}", syntax), + Error::InvalidParameter { param } => write!(f, "Invalid parameter: {}", param), + Error::UnsupportedParameter { param } => { + write!(f, "Unsupported parameter: {}", param) + } + Error::ResponseTooLong => write!(f, "Response too long"), + Error::InvalidResponse { code } => write!(f, "Invalid response: {}", code), + } + } +}