From 2ad0dd66dd6d42431ea491be29adb6a513d8d867 Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Thu, 10 Aug 2023 20:16:41 +0200 Subject: [PATCH] Replace format!("{}", jid) with jid.to_string() This is more readable I think, and expresses better our intent. --- jid/src/lib.rs | 47 ++++++++++++++++------------------------------- 1 file changed, 16 insertions(+), 31 deletions(-) diff --git a/jid/src/lib.rs b/jid/src/lib.rs index 92f5a52..291e53f 100644 --- a/jid/src/lib.rs +++ b/jid/src/lib.rs @@ -627,42 +627,42 @@ use minidom::{IntoAttributeValue, Node}; #[cfg(feature = "minidom")] impl IntoAttributeValue for Jid { fn into_attribute_value(self) -> Option { - Some(format!("{}", self)) + Some(self.to_string()) } } #[cfg(feature = "minidom")] impl From for Node { fn from(jid: Jid) -> Node { - Node::Text(format!("{}", jid)) + Node::Text(jid.to_string()) } } #[cfg(feature = "minidom")] impl IntoAttributeValue for FullJid { fn into_attribute_value(self) -> Option { - Some(format!("{}", self)) + Some(self.to_string()) } } #[cfg(feature = "minidom")] impl From for Node { fn from(jid: FullJid) -> Node { - Node::Text(format!("{}", jid)) + Node::Text(jid.to_string()) } } #[cfg(feature = "minidom")] impl IntoAttributeValue for BareJid { fn into_attribute_value(self) -> Option { - Some(format!("{}", self)) + Some(self.to_string()) } } #[cfg(feature = "minidom")] impl From for Node { fn from(jid: BareJid) -> Node { - Node::Text(format!("{}", jid)) + Node::Text(jid.to_string()) } } @@ -803,14 +803,8 @@ mod tests { #[test] fn serialise() { - assert_eq!( - format!("{}", FullJid::new("a@b/c").unwrap()), - String::from("a@b/c") - ); - assert_eq!( - format!("{}", BareJid::new("a@b").unwrap()), - String::from("a@b") - ); + assert_eq!(FullJid::new("a@b/c").unwrap().to_string(), "a@b/c"); + assert_eq!(BareJid::new("a@b").unwrap().to_string(), "a@b"); } #[test] @@ -839,22 +833,13 @@ mod tests { #[test] fn display_jids() { + assert_eq!(FullJid::new("a@b/c").unwrap().to_string(), "a@b/c"); + assert_eq!(BareJid::new("a@b").unwrap().to_string(), "a@b"); assert_eq!( - format!("{}", FullJid::new("a@b/c").unwrap()), - String::from("a@b/c") - ); - assert_eq!( - format!("{}", BareJid::new("a@b").unwrap()), - String::from("a@b") - ); - assert_eq!( - format!("{}", Jid::Full(FullJid::new("a@b/c").unwrap())), - String::from("a@b/c") - ); - assert_eq!( - format!("{}", Jid::Bare(BareJid::new("a@b").unwrap())), - String::from("a@b") + Jid::Full(FullJid::new("a@b/c").unwrap()).to_string(), + "a@b/c" ); + assert_eq!(Jid::Bare(BareJid::new("a@b").unwrap()).to_string(), "a@b"); } #[cfg(feature = "minidom")] @@ -884,19 +869,19 @@ mod tests { let elem = minidom::Element::builder("message", "jabber:client") .attr("from", full.clone()) .build(); - assert_eq!(elem.attr("from"), Some(format!("{}", full).as_str())); + assert_eq!(elem.attr("from"), Some(full.to_string().as_str())); let bare = BareJid::new("a@b").unwrap(); let elem = minidom::Element::builder("message", "jabber:client") .attr("from", bare.clone()) .build(); - assert_eq!(elem.attr("from"), Some(format!("{}", bare).as_str())); + assert_eq!(elem.attr("from"), Some(bare.to_string().as_str())); let jid = Jid::Bare(bare.clone()); let _elem = minidom::Element::builder("message", "jabber:client") .attr("from", jid) .build(); - assert_eq!(elem.attr("from"), Some(format!("{}", bare).as_str())); + assert_eq!(elem.attr("from"), Some(bare.to_string().as_str())); } #[test]