Replace format!("{}", jid) with jid.to_string()

This is more readable I think, and expresses better our intent.
This commit is contained in:
Emmanuel Gil Peyrot 2023-08-10 20:16:41 +02:00 committed by pep
parent 6fc3a46bd2
commit 2ad0dd66dd

View file

@ -627,42 +627,42 @@ use minidom::{IntoAttributeValue, Node};
#[cfg(feature = "minidom")] #[cfg(feature = "minidom")]
impl IntoAttributeValue for Jid { impl IntoAttributeValue for Jid {
fn into_attribute_value(self) -> Option<String> { fn into_attribute_value(self) -> Option<String> {
Some(format!("{}", self)) Some(self.to_string())
} }
} }
#[cfg(feature = "minidom")] #[cfg(feature = "minidom")]
impl From<Jid> for Node { impl From<Jid> for Node {
fn from(jid: Jid) -> Node { fn from(jid: Jid) -> Node {
Node::Text(format!("{}", jid)) Node::Text(jid.to_string())
} }
} }
#[cfg(feature = "minidom")] #[cfg(feature = "minidom")]
impl IntoAttributeValue for FullJid { impl IntoAttributeValue for FullJid {
fn into_attribute_value(self) -> Option<String> { fn into_attribute_value(self) -> Option<String> {
Some(format!("{}", self)) Some(self.to_string())
} }
} }
#[cfg(feature = "minidom")] #[cfg(feature = "minidom")]
impl From<FullJid> for Node { impl From<FullJid> for Node {
fn from(jid: FullJid) -> Node { fn from(jid: FullJid) -> Node {
Node::Text(format!("{}", jid)) Node::Text(jid.to_string())
} }
} }
#[cfg(feature = "minidom")] #[cfg(feature = "minidom")]
impl IntoAttributeValue for BareJid { impl IntoAttributeValue for BareJid {
fn into_attribute_value(self) -> Option<String> { fn into_attribute_value(self) -> Option<String> {
Some(format!("{}", self)) Some(self.to_string())
} }
} }
#[cfg(feature = "minidom")] #[cfg(feature = "minidom")]
impl From<BareJid> for Node { impl From<BareJid> for Node {
fn from(jid: BareJid) -> Node { fn from(jid: BareJid) -> Node {
Node::Text(format!("{}", jid)) Node::Text(jid.to_string())
} }
} }
@ -803,14 +803,8 @@ mod tests {
#[test] #[test]
fn serialise() { fn serialise() {
assert_eq!( assert_eq!(FullJid::new("a@b/c").unwrap().to_string(), "a@b/c");
format!("{}", FullJid::new("a@b/c").unwrap()), assert_eq!(BareJid::new("a@b").unwrap().to_string(), "a@b");
String::from("a@b/c")
);
assert_eq!(
format!("{}", BareJid::new("a@b").unwrap()),
String::from("a@b")
);
} }
#[test] #[test]
@ -839,22 +833,13 @@ mod tests {
#[test] #[test]
fn display_jids() { 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!( assert_eq!(
format!("{}", FullJid::new("a@b/c").unwrap()), Jid::Full(FullJid::new("a@b/c").unwrap()).to_string(),
String::from("a@b/c") "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")
); );
assert_eq!(Jid::Bare(BareJid::new("a@b").unwrap()).to_string(), "a@b");
} }
#[cfg(feature = "minidom")] #[cfg(feature = "minidom")]
@ -884,19 +869,19 @@ mod tests {
let elem = minidom::Element::builder("message", "jabber:client") let elem = minidom::Element::builder("message", "jabber:client")
.attr("from", full.clone()) .attr("from", full.clone())
.build(); .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 bare = BareJid::new("a@b").unwrap();
let elem = minidom::Element::builder("message", "jabber:client") let elem = minidom::Element::builder("message", "jabber:client")
.attr("from", bare.clone()) .attr("from", bare.clone())
.build(); .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 jid = Jid::Bare(bare.clone());
let _elem = minidom::Element::builder("message", "jabber:client") let _elem = minidom::Element::builder("message", "jabber:client")
.attr("from", jid) .attr("from", jid)
.build(); .build();
assert_eq!(elem.attr("from"), Some(format!("{}", bare).as_str())); assert_eq!(elem.attr("from"), Some(bare.to_string().as_str()));
} }
#[test] #[test]