stanza_error: Simplify serialisation.
This commit is contained in:
parent
2b9a6d57b6
commit
4f64754bdc
1 changed files with 11 additions and 14 deletions
|
@ -289,24 +289,21 @@ impl TryFrom<Element> for StanzaError {
|
||||||
|
|
||||||
impl From<StanzaError> for Element {
|
impl From<StanzaError> for Element {
|
||||||
fn from(err: StanzaError) -> Element {
|
fn from(err: StanzaError) -> Element {
|
||||||
let mut root = Element::builder("error")
|
Element::builder("error")
|
||||||
.ns(ns::DEFAULT_NS)
|
.ns(ns::DEFAULT_NS)
|
||||||
.attr("type", err.type_)
|
.attr("type", err.type_)
|
||||||
.attr("by", err.by)
|
.attr("by", err.by)
|
||||||
.append(err.defined_condition)
|
.append(err.defined_condition)
|
||||||
.build();
|
.append(
|
||||||
for (lang, text) in err.texts {
|
err.texts.into_iter().map(|(lang, text)| {
|
||||||
let elem = Element::builder("text")
|
Element::builder("text")
|
||||||
.ns(ns::XMPP_STANZAS)
|
.ns(ns::XMPP_STANZAS)
|
||||||
.attr("xml:lang", lang)
|
.attr("xml:lang", lang)
|
||||||
.append(text)
|
.append(text)
|
||||||
.build();
|
.build()
|
||||||
root.append_child(elem);
|
}).collect::<Vec<_>>())
|
||||||
}
|
.append(err.other)
|
||||||
if let Some(other) = err.other {
|
.build()
|
||||||
root.append_child(other);
|
|
||||||
}
|
|
||||||
root
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue