mirror of
https://gitlab.com/xmpp-rs/xmpp-rs.git
synced 2024-07-12 22:21:53 +00:00
stanza_error: Simplify with IntoElements.
This commit is contained in:
parent
56b7785942
commit
764a7190e9
2 changed files with 16 additions and 18 deletions
|
@ -99,12 +99,12 @@ impl FromStr for Creator {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<Creator> for String {
|
impl IntoAttributeValue for Creator {
|
||||||
fn from(creator: Creator) -> String {
|
fn into_attribute_value(self) -> Option<String> {
|
||||||
String::from(match creator {
|
Some(String::from(match self {
|
||||||
Creator::Initiator => "initiator",
|
Creator::Initiator => "initiator",
|
||||||
Creator::Responder => "responder",
|
Creator::Responder => "responder",
|
||||||
})
|
}))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -137,14 +137,14 @@ impl FromStr for Senders {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<Senders> for String {
|
impl IntoAttributeValue for Senders {
|
||||||
fn from(senders: Senders) -> String {
|
fn into_attribute_value(self) -> Option<String> {
|
||||||
String::from(match senders {
|
Some(String::from(match self {
|
||||||
Senders::Both => "both",
|
Senders::Both => "both",
|
||||||
Senders::Initiator => "initiator",
|
Senders::Initiator => "initiator",
|
||||||
Senders::None_ => "none",
|
Senders::None_ => "none",
|
||||||
Senders::Responder => "responder",
|
Senders::Responder => "responder",
|
||||||
})
|
}))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -202,10 +202,10 @@ impl Into<Element> for Content {
|
||||||
fn into(self) -> Element {
|
fn into(self) -> Element {
|
||||||
Element::builder("content")
|
Element::builder("content")
|
||||||
.ns(ns::JINGLE)
|
.ns(ns::JINGLE)
|
||||||
.attr("creator", String::from(self.creator))
|
.attr("creator", self.creator)
|
||||||
.attr("disposition", self.disposition)
|
.attr("disposition", self.disposition)
|
||||||
.attr("name", self.name)
|
.attr("name", self.name)
|
||||||
.attr("senders", String::from(self.senders))
|
.attr("senders", self.senders)
|
||||||
.append(self.description)
|
.append(self.description)
|
||||||
.append(self.transport)
|
.append(self.transport)
|
||||||
.append(self.security)
|
.append(self.security)
|
||||||
|
|
|
@ -8,7 +8,7 @@ use std::convert::TryFrom;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
use std::collections::BTreeMap;
|
use std::collections::BTreeMap;
|
||||||
|
|
||||||
use minidom::{Element, IntoAttributeValue};
|
use minidom::{Element, IntoElements, IntoAttributeValue, ElementEmitter};
|
||||||
|
|
||||||
use error::Error;
|
use error::Error;
|
||||||
use jid::Jid;
|
use jid::Jid;
|
||||||
|
@ -110,9 +110,9 @@ impl FromStr for DefinedCondition {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<DefinedCondition> for String {
|
impl IntoElements for DefinedCondition {
|
||||||
fn from(defined_condition: DefinedCondition) -> String {
|
fn into_elements(self, emitter: &mut ElementEmitter) {
|
||||||
String::from(match defined_condition {
|
emitter.append_child(Element::builder(match self {
|
||||||
DefinedCondition::BadRequest => "bad-request",
|
DefinedCondition::BadRequest => "bad-request",
|
||||||
DefinedCondition::Conflict => "conflict",
|
DefinedCondition::Conflict => "conflict",
|
||||||
DefinedCondition::FeatureNotImplemented => "feature-not-implemented",
|
DefinedCondition::FeatureNotImplemented => "feature-not-implemented",
|
||||||
|
@ -135,7 +135,7 @@ impl From<DefinedCondition> for String {
|
||||||
DefinedCondition::SubscriptionRequired => "subscription-required",
|
DefinedCondition::SubscriptionRequired => "subscription-required",
|
||||||
DefinedCondition::UndefinedCondition => "undefined-condition",
|
DefinedCondition::UndefinedCondition => "undefined-condition",
|
||||||
DefinedCondition::UnexpectedRequest => "unexpected-request",
|
DefinedCondition::UnexpectedRequest => "unexpected-request",
|
||||||
})
|
}).ns(ns::XMPP_STANZAS).build());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -207,9 +207,7 @@ impl Into<Element> for StanzaError {
|
||||||
.ns(ns::JABBER_CLIENT)
|
.ns(ns::JABBER_CLIENT)
|
||||||
.attr("type", self.type_)
|
.attr("type", self.type_)
|
||||||
.attr("by", self.by.and_then(|by| Some(String::from(by))))
|
.attr("by", self.by.and_then(|by| Some(String::from(by))))
|
||||||
.append(Element::builder(self.defined_condition)
|
.append(self.defined_condition)
|
||||||
.ns(ns::XMPP_STANZAS)
|
|
||||||
.build())
|
|
||||||
.build();
|
.build();
|
||||||
for (lang, text) in self.texts {
|
for (lang, text) in self.texts {
|
||||||
let elem = Element::builder("text")
|
let elem = Element::builder("text")
|
||||||
|
|
Loading…
Reference in a new issue