From a429a249134e15c508b094af004b126306359e6e Mon Sep 17 00:00:00 2001 From: Paolo Barbolini Date: Sun, 14 Mar 2021 10:17:07 +0100 Subject: [PATCH] Add missing Debug implementations (#570) --- src/executor.rs | 6 +++++- src/transport/smtp/async_transport.rs | 25 ++++++++++++++++++++----- src/transport/smtp/authentication.rs | 10 ++++++++-- src/transport/smtp/client/tls.rs | 24 ++++++++++++++++++++++-- src/transport/smtp/mod.rs | 3 +-- src/transport/smtp/transport.rs | 6 ++---- 6 files changed, 58 insertions(+), 16 deletions(-) diff --git a/src/executor.rs b/src/executor.rs index cdc004d..1a16019 100644 --- a/src/executor.rs +++ b/src/executor.rs @@ -1,5 +1,6 @@ use async_trait::async_trait; +use std::fmt::Debug; #[cfg(feature = "file-transport")] use std::io::Result as IoResult; #[cfg(feature = "file-transport")] @@ -39,7 +40,7 @@ use crate::transport::smtp::Error; doc(cfg(any(feature = "tokio02", feature = "tokio1", feature = "async-std1"))) )] #[async_trait] -pub trait Executor: Send + Sync + private::Sealed { +pub trait Executor: Debug + Send + Sync + private::Sealed { #[doc(hidden)] #[cfg(feature = "smtp-transport")] async fn connect( @@ -70,6 +71,7 @@ pub trait Executor: Send + Sync + private::Sealed { #[non_exhaustive] #[cfg(feature = "tokio02")] #[cfg_attr(docsrs, doc(cfg(feature = "tokio02")))] +#[derive(Debug)] pub struct Tokio02Executor; #[async_trait] @@ -135,6 +137,7 @@ impl Executor for Tokio02Executor { #[non_exhaustive] #[cfg(feature = "tokio1")] #[cfg_attr(docsrs, doc(cfg(feature = "tokio1")))] +#[derive(Debug)] pub struct Tokio1Executor; #[async_trait] @@ -199,6 +202,7 @@ impl Executor for Tokio1Executor { #[non_exhaustive] #[cfg(feature = "async-std1")] #[cfg_attr(docsrs, doc(cfg(feature = "async-std1")))] +#[derive(Debug)] pub struct AsyncStd1Executor; #[async_trait] diff --git a/src/transport/smtp/async_transport.rs b/src/transport/smtp/async_transport.rs index b277078..8895661 100644 --- a/src/transport/smtp/async_transport.rs +++ b/src/transport/smtp/async_transport.rs @@ -1,3 +1,4 @@ +use std::fmt::{self, Debug}; use std::marker::PhantomData; use async_trait::async_trait; @@ -20,7 +21,6 @@ use crate::{Envelope, Executor}; docsrs, doc(cfg(any(feature = "tokio02", feature = "tokio1", feature = "async-std1"))) )] -#[allow(missing_debug_implementations)] pub struct AsyncSmtpTransport { // TODO: pool inner: AsyncSmtpClient, @@ -184,6 +184,14 @@ where } } +impl Debug for AsyncSmtpTransport { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + let mut builder = f.debug_struct("AsyncSmtpTransport"); + builder.field("inner", &self.inner); + builder.finish() + } +} + impl Clone for AsyncSmtpTransport where E: Executor, @@ -197,8 +205,7 @@ where /// Contains client configuration. /// Instances of this struct can be created using functions of [`AsyncSmtpTransport`]. -#[allow(missing_debug_implementations)] -#[derive(Clone)] +#[derive(Debug, Clone)] #[cfg_attr( docsrs, doc(cfg(any(feature = "tokio02", feature = "tokio1", feature = "async-std1"))) @@ -271,9 +278,9 @@ impl AsyncSmtpTransportBuilder { } /// Build client -pub struct AsyncSmtpClient { +pub struct AsyncSmtpClient { info: SmtpInfo, - marker_: PhantomData, + marker_: PhantomData, } impl AsyncSmtpClient @@ -299,6 +306,14 @@ where } } +impl Debug for AsyncSmtpClient { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + let mut builder = f.debug_struct("AsyncSmtpClient"); + builder.field("info", &self.info); + builder.finish() + } +} + impl AsyncSmtpClient where E: Executor, diff --git a/src/transport/smtp/authentication.rs b/src/transport/smtp/authentication.rs index 71d181c..36b766b 100644 --- a/src/transport/smtp/authentication.rs +++ b/src/transport/smtp/authentication.rs @@ -1,14 +1,14 @@ //! Provides limited SASL authentication mechanisms use crate::transport::smtp::error::{self, Error}; -use std::fmt::{self, Display, Formatter}; +use std::fmt::{self, Debug, Display, Formatter}; /// Accepted authentication mechanisms /// Trying LOGIN last as it is deprecated. pub const DEFAULT_MECHANISMS: &[Mechanism] = &[Mechanism::Plain, Mechanism::Login]; /// Contains user credentials -#[derive(PartialEq, Eq, Clone, Hash, Debug)] +#[derive(PartialEq, Eq, Clone, Hash)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct Credentials { authentication_identity: String, @@ -35,6 +35,12 @@ where } } +impl Debug for Credentials { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + f.debug_struct("Credentials").finish() + } +} + /// Represents authentication mechanisms #[derive(PartialEq, Eq, Copy, Clone, Hash, Debug)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] diff --git a/src/transport/smtp/client/tls.rs b/src/transport/smtp/client/tls.rs index 861efc4..ed5d1e3 100644 --- a/src/transport/smtp/client/tls.rs +++ b/src/transport/smtp/client/tls.rs @@ -4,6 +4,7 @@ use crate::transport::smtp::{error, Error}; use native_tls::{Protocol, TlsConnector}; #[cfg(feature = "rustls-tls")] use rustls::{ClientConfig, RootCertStore, ServerCertVerified, ServerCertVerifier, TLSError}; +use std::fmt::{self, Debug}; #[cfg(feature = "rustls-tls")] use std::sync::Arc; #[cfg(feature = "rustls-tls")] @@ -32,9 +33,22 @@ pub enum Tls { Wrapper(TlsParameters), } +impl Debug for Tls { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match &self { + Self::None => f.pad("None"), + #[cfg(any(feature = "native-tls", feature = "rustls-tls"))] + Self::Opportunistic(_) => f.pad("Opportunistic"), + #[cfg(any(feature = "native-tls", feature = "rustls-tls"))] + Self::Required(_) => f.pad("Required"), + #[cfg(any(feature = "native-tls", feature = "rustls-tls"))] + Self::Wrapper(_) => f.pad("Wrapper"), + } + } +} + /// Parameters to use for secure clients #[derive(Clone)] -#[allow(missing_debug_implementations)] pub struct TlsParameters { pub(crate) connector: InnerTlsParameters, /// The domain name which is expected in the TLS certificate from the server @@ -42,7 +56,7 @@ pub struct TlsParameters { } /// Builder for `TlsParameters` -#[derive(Clone)] +#[derive(Debug, Clone)] pub struct TlsParametersBuilder { domain: String, root_certs: Vec, @@ -262,6 +276,12 @@ impl Certificate { } } +impl Debug for Certificate { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_struct("Certificate").finish() + } +} + #[cfg(feature = "rustls-tls")] struct InvalidCertsVerifier; diff --git a/src/transport/smtp/mod.rs b/src/transport/smtp/mod.rs index 9e80eef..4bd932e 100644 --- a/src/transport/smtp/mod.rs +++ b/src/transport/smtp/mod.rs @@ -166,8 +166,7 @@ pub const SUBMISSIONS_PORT: u16 = 465; /// Default timeout pub const DEFAULT_TIMEOUT: Duration = Duration::from_secs(60); -#[allow(missing_debug_implementations)] -#[derive(Clone)] +#[derive(Debug, Clone)] struct SmtpInfo { /// Name sent during EHLO hello_name: ClientId, diff --git a/src/transport/smtp/transport.rs b/src/transport/smtp/transport.rs index f3a6722..1055bff 100644 --- a/src/transport/smtp/transport.rs +++ b/src/transport/smtp/transport.rs @@ -12,7 +12,6 @@ use crate::{address::Envelope, Transport}; /// Sends emails using the SMTP protocol #[cfg_attr(docsrs, doc(cfg(feature = "smtp-transport")))] -#[allow(missing_debug_implementations)] #[derive(Clone)] pub struct SmtpTransport { #[cfg(feature = "r2d2")] @@ -112,8 +111,7 @@ impl SmtpTransport { /// Contains client configuration. /// Instances of this struct can be created using functions of [`SmtpTransport`]. -#[allow(missing_debug_implementations)] -#[derive(Clone)] +#[derive(Debug, Clone)] pub struct SmtpTransportBuilder { info: SmtpInfo, #[cfg(feature = "r2d2")] @@ -185,7 +183,7 @@ impl SmtpTransportBuilder { } /// Build client -#[derive(Clone)] +#[derive(Debug, Clone)] pub struct SmtpClient { info: SmtpInfo, }