client-api: Simplify Debug output of uiaa::AuthData

This commit is contained in:
Jonas Platte 2022-11-01 09:00:35 +01:00 committed by Jonas Platte
parent c68791a5d8
commit e271af0140

View File

@ -34,9 +34,9 @@ mod user_serde;
/// ///
/// To construct the custom `AuthData` variant you first have to construct [`IncomingAuthData::new`] /// To construct the custom `AuthData` variant you first have to construct [`IncomingAuthData::new`]
/// and then call [`IncomingAuthData::to_outgoing`] on it. /// and then call [`IncomingAuthData::to_outgoing`] on it.
#[derive(Clone, Debug, Incoming, Serialize)] #[derive(Clone, Incoming, Serialize)]
#[non_exhaustive] #[non_exhaustive]
#[incoming_derive(!Deserialize)] #[incoming_derive(!Debug, !Deserialize)]
#[serde(untagged)] #[serde(untagged)]
pub enum AuthData<'a> { pub enum AuthData<'a> {
/// Password-based authentication (`m.login.password`). /// Password-based authentication (`m.login.password`).
@ -140,6 +140,22 @@ impl<'a> AuthData<'a> {
} }
} }
impl fmt::Debug for AuthData<'_> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
// Print `Password { .. }` instead of `Password(Password { .. })`
match self {
Self::Password(inner) => inner.fmt(f),
Self::ReCaptcha(inner) => inner.fmt(f),
Self::EmailIdentity(inner) => inner.fmt(f),
Self::Msisdn(inner) => inner.fmt(f),
Self::Dummy(inner) => inner.fmt(f),
Self::RegistrationToken(inner) => inner.fmt(f),
Self::FallbackAcknowledgement(inner) => inner.fmt(f),
Self::_Custom(inner) => inner.fmt(f),
}
}
}
impl IncomingAuthData { impl IncomingAuthData {
/// Creates a new `IncomingAuthData` with the given `auth_type` string, session and data. /// Creates a new `IncomingAuthData` with the given `auth_type` string, session and data.
/// ///
@ -269,6 +285,22 @@ impl IncomingAuthData {
} }
} }
impl fmt::Debug for IncomingAuthData {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
// Print `Password { .. }` instead of `Password(Password { .. })`
match self {
Self::Password(inner) => inner.fmt(f),
Self::ReCaptcha(inner) => inner.fmt(f),
Self::EmailIdentity(inner) => inner.fmt(f),
Self::Msisdn(inner) => inner.fmt(f),
Self::Dummy(inner) => inner.fmt(f),
Self::RegistrationToken(inner) => inner.fmt(f),
Self::FallbackAcknowledgement(inner) => inner.fmt(f),
Self::_Custom(inner) => inner.fmt(f),
}
}
}
impl<'de> Deserialize<'de> for IncomingAuthData { impl<'de> Deserialize<'de> for IncomingAuthData {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where where