From 0288b937df2ba5ba2e89a389fdba0d8087f9061e Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Sun, 30 Apr 2017 21:44:02 +0100 Subject: [PATCH 1/2] Simplify the Display implementation. --- src/lib.rs | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index fead7e7..37d43fa 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -52,14 +52,7 @@ impl From for String { impl fmt::Display for Jid { fn fmt(&self, fmt: &mut fmt::Formatter) -> Result<(), fmt::Error> { - // TODO: may need escaping - if let Some(ref node) = self.node { - write!(fmt, "{}@", node)?; - } - write!(fmt, "{}", self.domain)?; - if let Some(ref resource) = self.resource { - write!(fmt, "/{}", resource)?; - } + fmt.write_str(String::from(self.clone()).as_ref())?; Ok(()) } } From c13cebf02587390dabbd48f04f4e686c63a6c1b2 Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Sun, 30 Apr 2017 21:44:17 +0100 Subject: [PATCH 2/2] Implement the Debug trait in a more user-friendly way. --- src/lib.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 37d43fa..04f8c2e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -24,7 +24,7 @@ pub enum JidParseError { /// - A node/name, `node`, which is the optional part before the @. /// - A domain, `domain`, which is the mandatory part after the @ but before the /. /// - A resource, `resource`, which is the optional part after the /. -#[derive(Debug, Clone, PartialEq, Eq)] +#[derive(Clone, PartialEq, Eq)] pub struct Jid { /// The node part of the Jabber ID, if it exists, else None. pub node: Option, @@ -50,6 +50,13 @@ impl From for String { } } +impl fmt::Debug for Jid { + fn fmt(&self, fmt: &mut fmt::Formatter) -> Result<(), fmt::Error> { + write!(fmt, "JID({})", self)?; + Ok(()) + } +} + impl fmt::Display for Jid { fn fmt(&self, fmt: &mut fmt::Formatter) -> Result<(), fmt::Error> { fmt.write_str(String::from(self.clone()).as_ref())?;