message: Remove extra clones, and simplify Into<Element>.

This commit is contained in:
Emmanuel Gil Peyrot 2017-05-24 21:40:11 +01:00
parent 8182213666
commit 453a3635fd

View file

@ -97,7 +97,7 @@ impl Into<Element> for MessagePayload {
MessagePayload::StanzaId(stanza_id) => stanza_id.into(),
MessagePayload::MamResult(result) => result.into(),
MessagePayload::Unknown(elem) => elem.clone(),
MessagePayload::Unknown(elem) => elem,
}
}
}
@ -221,12 +221,12 @@ impl TryFrom<Element> for Message {
impl Into<Element> for Message {
fn into(self) -> Element {
let mut stanza = Element::builder("message")
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())
.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")
@ -235,7 +235,7 @@ impl Into<Element> for Message {
"" => None,
lang => Some(lang),
})
.append(subject.clone())
.append(subject)
.build() })
.collect::<Vec<_>>())
.append(self.bodies.iter()
@ -246,14 +246,11 @@ impl Into<Element> for Message {
"" => None,
lang => Some(lang),
})
.append(body.clone())
.append(body)
.build() })
.collect::<Vec<_>>())
.build();
for child in self.payloads.clone() {
stanza.append_child(child);
}
stanza
.append(self.payloads)
.build()
}
}