From 56986a68e48dffbb875bb040a009939636d978d5 Mon Sep 17 00:00:00 2001 From: Randy von der Weide Date: Sat, 31 Aug 2019 13:17:51 +0000 Subject: [PATCH] Impl Display for Jid --- src/lib.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index c55c806..abe475e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -92,6 +92,12 @@ impl From for Jid { } } +impl fmt::Display for Jid { + fn fmt(&self, fmt: &mut fmt::Formatter) -> Result<(), fmt::Error> { + fmt.write_str(String::from(self.clone()).as_ref()) + } +} + impl Jid { /// The node part of the Jabber ID, if it exists, else None. pub fn node(self) -> Option { @@ -696,6 +702,14 @@ mod tests { assert_eq!(FullJid::from_str("a@b"), Err(JidParseError::NoResource)); } + #[test] + fn display_jids() { + assert_eq!(format!("{}", FullJid::new("a", "b", "c")), String::from("a@b/c")); + assert_eq!(format!("{}", BareJid::new("a", "b")), String::from("a@b")); + assert_eq!(format!("{}", Jid::Full(FullJid::new("a", "b", "c"))), String::from("a@b/c")); + assert_eq!(format!("{}", Jid::Bare(BareJid::new("a", "b"))), String::from("a@b")); + } + #[cfg(feature = "minidom")] #[test] fn minidom() {