From: Greg Burri Date: Thu, 27 Mar 2025 16:32:56 +0000 (+0100) Subject: Use thiserror crate for email (instead of manually implementing all 'From' traits) X-Git-Url: https://git.euphorik.ch/?a=commitdiff_plain;h=b8a8af39795ab69fb2241884f89e8a059f59d24f;p=recipes.git Use thiserror crate for email (instead of manually implementing all 'From' traits) --- diff --git a/backend/src/email.rs b/backend/src/email.rs index 32cf5c3..d9c0ea4 100644 --- a/backend/src/email.rs +++ b/backend/src/email.rs @@ -1,37 +1,22 @@ -use derive_more::Display; use lettre::{ - transport::smtp::{authentication::Credentials, AsyncSmtpTransport}, AsyncTransport, Message, Tokio1Executor, + transport::smtp::{AsyncSmtpTransport, authentication::Credentials}, }; -use tracing::{event, Level}; +use tracing::{Level, event}; use crate::consts; -#[derive(Debug, Display)] +#[derive(Debug, thiserror::Error)] pub enum Error { - Parse(lettre::address::AddressError), - Smtp(lettre::transport::smtp::Error), - Email(lettre::error::Error), -} - -impl From for Error { - fn from(error: lettre::address::AddressError) -> Self { - Error::Parse(error) - } -} + #[error("Parse error: {0}")] + Parse(#[from] lettre::address::AddressError), -impl From for Error { - fn from(error: lettre::transport::smtp::Error) -> Self { - Error::Smtp(error) - } -} + #[error("SMTP error: {0}")] + Smtp(#[from] lettre::transport::smtp::Error), -impl From for Error { - fn from(error: lettre::error::Error) -> Self { - Error::Email(error) - } + #[error("Email error: {0}")] + Email(#[from] lettre::error::Error), } - pub async fn send_email( email: &str, message: &str,