diff --git a/src/transport/smtp/async_transport.rs b/src/transport/smtp/async_transport.rs index 6ec2b23..e144841 100644 --- a/src/transport/smtp/async_transport.rs +++ b/src/transport/smtp/async_transport.rs @@ -1,3 +1,5 @@ +use std::marker::PhantomData; + use async_trait::async_trait; #[cfg(any(feature = "tokio02", feature = "tokio1", feature = "async-std1"))] @@ -14,7 +16,6 @@ use crate::Tokio02Transport; use crate::Tokio1Transport; #[allow(missing_debug_implementations)] -#[derive(Clone)] pub struct AsyncSmtpTransport { // TODO: pool inner: AsyncSmtpClient, @@ -158,6 +159,17 @@ where } } +impl Clone for AsyncSmtpTransport +where + C: AsyncSmtpConnector, +{ + fn clone(&self) -> Self { + Self { + inner: self.inner.clone(), + } + } +} + /// Contains client configuration. /// Instances of this struct can be created using functions of [`AsyncSmtpTransport`]. #[allow(missing_debug_implementations)] @@ -211,20 +223,18 @@ impl AsyncSmtpTransportBuilder { where C: AsyncSmtpConnector, { - let connector = Default::default(); let client = AsyncSmtpClient { - connector, info: self.info, + marker_: PhantomData, }; AsyncSmtpTransport { inner: client } } } /// Build client -#[derive(Clone)] pub struct AsyncSmtpClient { - connector: C, info: SmtpInfo, + marker_: PhantomData, } impl AsyncSmtpClient @@ -250,8 +260,21 @@ where } } +impl AsyncSmtpClient +where + C: AsyncSmtpConnector, +{ + fn clone(&self) -> Self { + Self { + info: self.info.clone(), + marker_: PhantomData, + } + } +} + #[async_trait] -pub trait AsyncSmtpConnector: Default + private::Sealed { +pub trait AsyncSmtpConnector: private::Sealed { + #[doc(hidden)] async fn connect( hostname: &str, port: u16, @@ -260,7 +283,8 @@ pub trait AsyncSmtpConnector: Default + private::Sealed { ) -> Result; } -#[derive(Debug, Copy, Clone, Default)] +#[allow(missing_copy_implementations)] +#[non_exhaustive] #[cfg(feature = "tokio02")] #[cfg_attr(docsrs, doc(cfg(feature = "tokio02")))] pub struct Tokio02Connector; @@ -268,6 +292,7 @@ pub struct Tokio02Connector; #[async_trait] #[cfg(feature = "tokio02")] impl AsyncSmtpConnector for Tokio02Connector { + #[doc(hidden)] async fn connect( hostname: &str, port: u16, @@ -302,7 +327,8 @@ impl AsyncSmtpConnector for Tokio02Connector { } } -#[derive(Debug, Copy, Clone, Default)] +#[allow(missing_copy_implementations)] +#[non_exhaustive] #[cfg(feature = "tokio1")] #[cfg_attr(docsrs, doc(cfg(feature = "tokio1")))] pub struct Tokio1Connector; @@ -310,6 +336,7 @@ pub struct Tokio1Connector; #[async_trait] #[cfg(feature = "tokio1")] impl AsyncSmtpConnector for Tokio1Connector { + #[doc(hidden)] async fn connect( hostname: &str, port: u16, @@ -343,7 +370,8 @@ impl AsyncSmtpConnector for Tokio1Connector { } } -#[derive(Debug, Copy, Clone, Default)] +#[allow(missing_copy_implementations)] +#[non_exhaustive] #[cfg(feature = "async-std1")] #[cfg_attr(docsrs, doc(cfg(feature = "async-std1")))] pub struct AsyncStd1Connector; @@ -351,6 +379,7 @@ pub struct AsyncStd1Connector; #[async_trait] #[cfg(feature = "async-std1")] impl AsyncSmtpConnector for AsyncStd1Connector { + #[doc(hidden)] async fn connect( hostname: &str, port: u16,