From 9960cfd9650c4a92b60a029dc69be9598c416889 Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Tue, 6 Aug 2024 16:29:05 +0200 Subject: [PATCH] jid: Make Debug more readable on Jid Jid("foo@bar/baz") instead of Jid { normalized: "foo@bar/baz", at: Some(3), slash: Some(7) }, which I find much more readable. Same for BareJid and FullJid. --- jid/src/lib.rs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/jid/src/lib.rs b/jid/src/lib.rs index caa9049a..b8b2c916 100644 --- a/jid/src/lib.rs +++ b/jid/src/lib.rs @@ -91,7 +91,7 @@ fn length_check(len: usize, error_empty: Error, error_too_long: Error) -> Result /// /// This dynamic type on the other hand can be used in contexts where it is /// not known, at compile-time, whether a JID is full or bare. -#[derive(Debug, Clone, Eq)] +#[derive(Clone, Eq)] pub struct Jid { normalized: String, at: Option, @@ -531,15 +531,25 @@ impl Borrow for BareJid { } } +impl fmt::Debug for Jid { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt.debug_tuple("Jid").field(&self.normalized).finish() + } +} + impl fmt::Debug for FullJid { fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { - fmt.debug_tuple("FullJid").field(&self.inner).finish() + fmt.debug_tuple("FullJid") + .field(&self.inner.normalized) + .finish() } } impl fmt::Debug for BareJid { fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { - fmt.debug_tuple("BareJid").field(&self.inner).finish() + fmt.debug_tuple("BareJid") + .field(&self.inner.normalized) + .finish() } }