Skip to content

Commit

Permalink
Added Display to Error
Browse files Browse the repository at this point in the history
  • Loading branch information
mdecimus committed May 22, 2023
1 parent 72fd0e2 commit 434ede7
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,3 +320,23 @@ impl<T: Display> AsRef<EhloResponse<T>> for EhloResponse<T> {
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),
}
}
}

0 comments on commit 434ede7

Please sign in to comment.