From 4f64754bdcd45712d37a71587fe538d84287b060 Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Thu, 28 Feb 2019 02:44:31 +0100 Subject: [PATCH] stanza_error: Simplify serialisation. --- src/stanza_error.rs | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/src/stanza_error.rs b/src/stanza_error.rs index 4c09eea7..fdc0d522 100644 --- a/src/stanza_error.rs +++ b/src/stanza_error.rs @@ -289,24 +289,21 @@ impl TryFrom for StanzaError { impl From for Element { fn from(err: StanzaError) -> Element { - let mut root = Element::builder("error") + Element::builder("error") .ns(ns::DEFAULT_NS) .attr("type", err.type_) .attr("by", err.by) .append(err.defined_condition) - .build(); - for (lang, text) in err.texts { - let elem = Element::builder("text") - .ns(ns::XMPP_STANZAS) - .attr("xml:lang", lang) - .append(text) - .build(); - root.append_child(elem); - } - if let Some(other) = err.other { - root.append_child(other); - } - root + .append( + err.texts.into_iter().map(|(lang, text)| { + Element::builder("text") + .ns(ns::XMPP_STANZAS) + .attr("xml:lang", lang) + .append(text) + .build() + }).collect::>()) + .append(err.other) + .build() } }