message: Remove extra clones, and simplify Into<Element>.
This commit is contained in:
parent
8182213666
commit
453a3635fd
1 changed files with 31 additions and 34 deletions
|
@ -97,7 +97,7 @@ impl Into<Element> for MessagePayload {
|
||||||
MessagePayload::StanzaId(stanza_id) => stanza_id.into(),
|
MessagePayload::StanzaId(stanza_id) => stanza_id.into(),
|
||||||
MessagePayload::MamResult(result) => result.into(),
|
MessagePayload::MamResult(result) => result.into(),
|
||||||
|
|
||||||
MessagePayload::Unknown(elem) => elem.clone(),
|
MessagePayload::Unknown(elem) => elem,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -221,39 +221,36 @@ impl TryFrom<Element> for Message {
|
||||||
|
|
||||||
impl Into<Element> for Message {
|
impl Into<Element> for Message {
|
||||||
fn into(self) -> Element {
|
fn into(self) -> Element {
|
||||||
let mut stanza = Element::builder("message")
|
Element::builder("message")
|
||||||
.ns(ns::JABBER_CLIENT)
|
.ns(ns::JABBER_CLIENT)
|
||||||
.attr("from", self.from.clone().and_then(|value| Some(String::from(value))))
|
.attr("from", self.from.and_then(|value| Some(String::from(value))))
|
||||||
.attr("to", self.to.clone().and_then(|value| Some(String::from(value))))
|
.attr("to", self.to.and_then(|value| Some(String::from(value))))
|
||||||
.attr("id", self.id.clone())
|
.attr("id", self.id)
|
||||||
.attr("type", self.type_.clone())
|
.attr("type", self.type_)
|
||||||
.append(self.subjects.iter()
|
.append(self.subjects.iter()
|
||||||
.map(|(lang, subject)| {
|
.map(|(lang, subject)| {
|
||||||
Element::builder("subject")
|
Element::builder("subject")
|
||||||
.ns(ns::JABBER_CLIENT)
|
.ns(ns::JABBER_CLIENT)
|
||||||
.attr("xml:lang", match lang.as_ref() {
|
.attr("xml:lang", match lang.as_ref() {
|
||||||
"" => None,
|
"" => None,
|
||||||
lang => Some(lang),
|
lang => Some(lang),
|
||||||
})
|
})
|
||||||
.append(subject.clone())
|
.append(subject)
|
||||||
.build() })
|
.build() })
|
||||||
.collect::<Vec<_>>())
|
.collect::<Vec<_>>())
|
||||||
.append(self.bodies.iter()
|
.append(self.bodies.iter()
|
||||||
.map(|(lang, body)| {
|
.map(|(lang, body)| {
|
||||||
Element::builder("body")
|
Element::builder("body")
|
||||||
.ns(ns::JABBER_CLIENT)
|
.ns(ns::JABBER_CLIENT)
|
||||||
.attr("xml:lang", match lang.as_ref() {
|
.attr("xml:lang", match lang.as_ref() {
|
||||||
"" => None,
|
"" => None,
|
||||||
lang => Some(lang),
|
lang => Some(lang),
|
||||||
})
|
})
|
||||||
.append(body.clone())
|
.append(body)
|
||||||
.build() })
|
.build() })
|
||||||
.collect::<Vec<_>>())
|
.collect::<Vec<_>>())
|
||||||
.build();
|
.append(self.payloads)
|
||||||
for child in self.payloads.clone() {
|
.build()
|
||||||
stanza.append_child(child);
|
|
||||||
}
|
|
||||||
stanza
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue