From 453a3635fda8034c9f8a6da817f5be87d8cded20 Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Wed, 24 May 2017 21:40:11 +0100 Subject: [PATCH] message: Remove extra clones, and simplify Into. --- src/message.rs | 65 ++++++++++++++++++++++++-------------------------- 1 file changed, 31 insertions(+), 34 deletions(-) diff --git a/src/message.rs b/src/message.rs index bc8a003..13caed3 100644 --- a/src/message.rs +++ b/src/message.rs @@ -97,7 +97,7 @@ impl Into for MessagePayload { MessagePayload::StanzaId(stanza_id) => stanza_id.into(), MessagePayload::MamResult(result) => result.into(), - MessagePayload::Unknown(elem) => elem.clone(), + MessagePayload::Unknown(elem) => elem, } } } @@ -221,39 +221,36 @@ impl TryFrom for Message { impl Into for Message { fn into(self) -> Element { - let mut stanza = Element::builder("message") - .ns(ns::JABBER_CLIENT) - .attr("from", self.from.clone().and_then(|value| Some(String::from(value)))) - .attr("to", self.to.clone().and_then(|value| Some(String::from(value)))) - .attr("id", self.id.clone()) - .attr("type", self.type_.clone()) - .append(self.subjects.iter() - .map(|(lang, subject)| { - Element::builder("subject") - .ns(ns::JABBER_CLIENT) - .attr("xml:lang", match lang.as_ref() { - "" => None, - lang => Some(lang), - }) - .append(subject.clone()) - .build() }) - .collect::>()) - .append(self.bodies.iter() - .map(|(lang, body)| { - Element::builder("body") - .ns(ns::JABBER_CLIENT) - .attr("xml:lang", match lang.as_ref() { - "" => None, - lang => Some(lang), - }) - .append(body.clone()) - .build() }) - .collect::>()) - .build(); - for child in self.payloads.clone() { - stanza.append_child(child); - } - stanza + Element::builder("message") + .ns(ns::JABBER_CLIENT) + .attr("from", self.from.and_then(|value| Some(String::from(value)))) + .attr("to", self.to.and_then(|value| Some(String::from(value)))) + .attr("id", self.id) + .attr("type", self.type_) + .append(self.subjects.iter() + .map(|(lang, subject)| { + Element::builder("subject") + .ns(ns::JABBER_CLIENT) + .attr("xml:lang", match lang.as_ref() { + "" => None, + lang => Some(lang), + }) + .append(subject) + .build() }) + .collect::>()) + .append(self.bodies.iter() + .map(|(lang, body)| { + Element::builder("body") + .ns(ns::JABBER_CLIENT) + .attr("xml:lang", match lang.as_ref() { + "" => None, + lang => Some(lang), + }) + .append(body) + .build() }) + .collect::>()) + .append(self.payloads) + .build() } }