From 2b624c264e8f53eb14a5990fd78a5ecf7b2570d5 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Tue, 1 Nov 2022 08:19:56 +0100 Subject: [PATCH] client-api: Simplify Debug output for LoginInfo --- crates/ruma-client-api/src/session/login.rs | 28 +++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/crates/ruma-client-api/src/session/login.rs b/crates/ruma-client-api/src/session/login.rs index fb744582..ac215eda 100644 --- a/crates/ruma-client-api/src/session/login.rs +++ b/crates/ruma-client-api/src/session/login.rs @@ -140,9 +140,9 @@ pub mod v3 { /// /// To construct the custom `LoginInfo` variant you first have to construct /// [`IncomingLoginInfo::new`] and then call [`IncomingLoginInfo::to_outgoing`] on it. - #[derive(Clone, Debug, Incoming, Serialize)] + #[derive(Clone, Incoming, Serialize)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] - #[incoming_derive(!Deserialize)] + #[incoming_derive(!Debug, !Deserialize)] #[serde(untagged)] pub enum LoginInfo<'a> { /// An identifier and password are supplied to authenticate. @@ -158,6 +158,18 @@ pub mod v3 { _Custom(CustomLoginInfo<'a>), } + impl fmt::Debug for LoginInfo<'_> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + // Print `Password { .. }` instead of `Password(Password { .. })` + match self { + Self::Password(inner) => inner.fmt(f), + Self::Token(inner) => inner.fmt(f), + Self::ApplicationService(inner) => inner.fmt(f), + Self::_Custom(inner) => inner.fmt(f), + } + } + } + impl IncomingLoginInfo { /// Creates a new `IncomingLoginInfo` with the given `login_type` string, session and data. /// @@ -199,6 +211,18 @@ pub mod v3 { } } + impl fmt::Debug for IncomingLoginInfo { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + // Print `Password { .. }` instead of `Password(Password { .. })` + match self { + Self::Password(inner) => inner.fmt(f), + Self::Token(inner) => inner.fmt(f), + Self::ApplicationService(inner) => inner.fmt(f), + Self::_Custom(inner) => inner.fmt(f), + } + } + } + impl<'de> Deserialize<'de> for IncomingLoginInfo { fn deserialize(deserializer: D) -> Result where