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 {
|
||||
fn from(creator: Creator) -> String {
|
||||
String::from(match creator {
|
||||
impl IntoAttributeValue for Creator {
|
||||
fn into_attribute_value(self) -> Option<String> {
|
||||
Some(String::from(match self {
|
||||
Creator::Initiator => "initiator",
|
||||
Creator::Responder => "responder",
|
||||
})
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -137,14 +137,14 @@ impl FromStr for Senders {
|
|||
}
|
||||
}
|
||||
|
||||
impl From<Senders> for String {
|
||||
fn from(senders: Senders) -> String {
|
||||
String::from(match senders {
|
||||
impl IntoAttributeValue for Senders {
|
||||
fn into_attribute_value(self) -> Option<String> {
|
||||
Some(String::from(match self {
|
||||
Senders::Both => "both",
|
||||
Senders::Initiator => "initiator",
|
||||
Senders::None_ => "none",
|
||||
Senders::Responder => "responder",
|
||||
})
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -202,10 +202,10 @@ impl Into<Element> for Content {
|
|||
fn into(self) -> Element {
|
||||
Element::builder("content")
|
||||
.ns(ns::JINGLE)
|
||||
.attr("creator", String::from(self.creator))
|
||||
.attr("creator", self.creator)
|
||||
.attr("disposition", self.disposition)
|
||||
.attr("name", self.name)
|
||||
.attr("senders", String::from(self.senders))
|
||||
.attr("senders", self.senders)
|
||||
.append(self.description)
|
||||
.append(self.transport)
|
||||
.append(self.security)
|
||||
|
|
|
@ -8,7 +8,7 @@ use std::convert::TryFrom;
|
|||
use std::str::FromStr;
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
use minidom::{Element, IntoAttributeValue};
|
||||
use minidom::{Element, IntoElements, IntoAttributeValue, ElementEmitter};
|
||||
|
||||
use error::Error;
|
||||
use jid::Jid;
|
||||
|
@ -110,9 +110,9 @@ impl FromStr for DefinedCondition {
|
|||
}
|
||||
}
|
||||
|
||||
impl From<DefinedCondition> for String {
|
||||
fn from(defined_condition: DefinedCondition) -> String {
|
||||
String::from(match defined_condition {
|
||||
impl IntoElements for DefinedCondition {
|
||||
fn into_elements(self, emitter: &mut ElementEmitter) {
|
||||
emitter.append_child(Element::builder(match self {
|
||||
DefinedCondition::BadRequest => "bad-request",
|
||||
DefinedCondition::Conflict => "conflict",
|
||||
DefinedCondition::FeatureNotImplemented => "feature-not-implemented",
|
||||
|
@ -135,7 +135,7 @@ impl From<DefinedCondition> for String {
|
|||
DefinedCondition::SubscriptionRequired => "subscription-required",
|
||||
DefinedCondition::UndefinedCondition => "undefined-condition",
|
||||
DefinedCondition::UnexpectedRequest => "unexpected-request",
|
||||
})
|
||||
}).ns(ns::XMPP_STANZAS).build());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -207,9 +207,7 @@ impl Into<Element> for StanzaError {
|
|||
.ns(ns::JABBER_CLIENT)
|
||||
.attr("type", self.type_)
|
||||
.attr("by", self.by.and_then(|by| Some(String::from(by))))
|
||||
.append(Element::builder(self.defined_condition)
|
||||
.ns(ns::XMPP_STANZAS)
|
||||
.build())
|
||||
.append(self.defined_condition)
|
||||
.build();
|
||||
for (lang, text) in self.texts {
|
||||
let elem = Element::builder("text")
|
||||
|
|
Loading…
Reference in a new issue