diff --git a/src/transport/smtp/authentication.rs b/src/transport/smtp/authentication.rs index 75e3195..5c5b384 100644 --- a/src/transport/smtp/authentication.rs +++ b/src/transport/smtp/authentication.rs @@ -7,25 +7,6 @@ use std::fmt::{self, Display, Formatter}; /// Trying LOGIN last as it is deprecated. pub const DEFAULT_MECHANISMS: &[Mechanism] = &[Mechanism::Plain, Mechanism::Login]; -/// Convertible to user credentials -pub trait IntoCredentials { - /// Converts to a `Credentials` struct - fn into_credentials(self) -> Credentials; -} - -impl IntoCredentials for Credentials { - fn into_credentials(self) -> Credentials { - self - } -} - -impl, T: Into> IntoCredentials for (S, T) { - fn into_credentials(self) -> Credentials { - let (username, password) = self; - Credentials::new(username.into(), password.into()) - } -} - /// Contains user credentials #[derive(PartialEq, Eq, Clone, Hash, Debug)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] @@ -44,6 +25,16 @@ impl Credentials { } } +impl From<(S, T)> for Credentials +where + S: Into, + T: Into, +{ + fn from((username, password): (S, T)) -> Self { + Credentials::new(username.into(), password.into()) + } +} + /// Represents authentication mechanisms #[derive(PartialEq, Eq, Copy, Clone, Hash, Debug)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] @@ -168,4 +159,12 @@ mod test { ); assert!(mechanism.response(&credentials, Some("test")).is_err()); } + + #[test] + fn test_from_user_pass_for_credentials() { + assert_eq!( + Credentials::new("alice".to_string(), "wonderland".to_string()), + Credentials::from(("alice", "wonderland")) + ); + } }