Replace Into<Element> with From<…> for Element.

This allows Element::from() to work, and since Into<Element> is
automatically implemented for any type implementing From there is no
change to existing code.
This commit is contained in:
Emmanuel Gil Peyrot 2017-07-20 20:36:13 +01:00
commit 487dbdc6de
28 changed files with 266 additions and 265 deletions

View file

@ -32,8 +32,8 @@ impl TryFrom<Element> for Attention {
} }
} }
impl Into<Element> for Attention { impl From<Attention> for Element {
fn into(self) -> Element { fn from(_: Attention) -> Element {
Element::builder("attention") Element::builder("attention")
.ns(ns::ATTENTION) .ns(ns::ATTENTION)
.build() .build()

View file

@ -45,9 +45,9 @@ impl TryFrom<Element> for ChatState {
} }
} }
impl Into<Element> for ChatState { impl From<ChatState> for Element {
fn into(self) -> Element { fn from(chatstate: ChatState) -> Element {
Element::builder(match self { Element::builder(match chatstate {
ChatState::Active => "active", ChatState::Active => "active",
ChatState::Composing => "composing", ChatState::Composing => "composing",
ChatState::Gone => "gone", ChatState::Gone => "gone",

View file

@ -45,13 +45,13 @@ impl TryFrom<Element> for Delay {
} }
} }
impl Into<Element> for Delay { impl From<Delay> for Element {
fn into(self) -> Element { fn from(delay: Delay) -> Element {
Element::builder("delay") Element::builder("delay")
.ns(ns::DELAY) .ns(ns::DELAY)
.attr("from", self.from.and_then(|value| Some(String::from(value)))) .attr("from", delay.from.and_then(|value| Some(String::from(value))))
.attr("stamp", self.stamp.to_rfc3339()) .attr("stamp", delay.stamp.to_rfc3339())
.append(self.data) .append(delay.data)
.build() .build()
} }
} }

View file

@ -53,11 +53,11 @@ pub struct Feature {
pub var: String, pub var: String,
} }
impl Into<Element> for Feature { impl From<Feature> for Element {
fn into(self) -> Element { fn from(feature: Feature) -> Element {
Element::builder("feature") Element::builder("feature")
.ns(ns::DISCO_INFO) .ns(ns::DISCO_INFO)
.attr("var", self.var) .attr("var", feature.var)
.build() .build()
} }
} }
@ -76,14 +76,14 @@ pub struct Identity {
pub name: Option<String>, pub name: Option<String>,
} }
impl Into<Element> for Identity { impl From<Identity> for Element {
fn into(self) -> Element { fn from(identity: Identity) -> Element {
Element::builder("identity") Element::builder("identity")
.ns(ns::DISCO_INFO) .ns(ns::DISCO_INFO)
.attr("category", self.category) .attr("category", identity.category)
.attr("type", self.type_) .attr("type", identity.type_)
.attr("xml:lang", self.lang) .attr("xml:lang", identity.lang)
.attr("name", self.name) .attr("name", identity.name)
.build() .build()
} }
} }
@ -174,16 +174,16 @@ impl TryFrom<Element> for DiscoInfoResult {
} }
} }
impl Into<Element> for DiscoInfoResult { impl From<DiscoInfoResult> for Element {
fn into(self) -> Element { fn from(disco: DiscoInfoResult) -> Element {
for _ in self.extensions { for _ in disco.extensions {
panic!("Not yet implemented!"); panic!("Not yet implemented!");
} }
Element::builder("query") Element::builder("query")
.ns(ns::DISCO_INFO) .ns(ns::DISCO_INFO)
.attr("node", self.node) .attr("node", disco.node)
.append(self.identities) .append(disco.identities)
.append(self.features) .append(disco.features)
.build() .build()
} }
} }

View file

@ -47,13 +47,13 @@ impl TryFrom<Element> for ECaps2 {
} }
} }
impl Into<Element> for ECaps2 { impl From<ECaps2> for Element {
fn into(mut self) -> Element { fn from(mut ecaps2: ECaps2) -> Element {
Element::builder("c") Element::builder("c")
.ns(ns::ECAPS2) .ns(ns::ECAPS2)
.append(self.hashes.drain(..) .append(ecaps2.hashes.drain(..)
.map(|hash| hash.into()) .map(|hash| hash.into())
.collect::<Vec<Element>>()) .collect::<Vec<Element>>())
.build() .build()
} }
} }

View file

@ -35,12 +35,12 @@ impl TryFrom<Element> for ExplicitMessageEncryption {
} }
} }
impl Into<Element> for ExplicitMessageEncryption { impl From<ExplicitMessageEncryption> for Element {
fn into(self) -> Element { fn from(eme: ExplicitMessageEncryption) -> Element {
Element::builder("encryption") Element::builder("encryption")
.ns(ns::EME) .ns(ns::EME)
.attr("namespace", self.namespace) .attr("namespace", eme.namespace)
.attr("name", self.name) .attr("name", eme.name)
.build() .build()
} }
} }

View file

@ -48,12 +48,12 @@ impl TryFrom<Element> for Forwarded {
} }
} }
impl Into<Element> for Forwarded { impl From<Forwarded> for Element {
fn into(self) -> Element { fn from(forwarded: Forwarded) -> Element {
Element::builder("forwarded") Element::builder("forwarded")
.ns(ns::FORWARD) .ns(ns::FORWARD)
.append(match self.delay { Some(delay) => { let elem: Element = delay.into(); Some(elem) }, None => None }) .append(match forwarded.delay { Some(delay) => { let elem: Element = delay.into(); Some(elem) }, None => None })
.append(match self.stanza { Some(stanza) => { let elem: Element = stanza.into(); Some(elem) }, None => None }) .append(match forwarded.stanza { Some(stanza) => { let elem: Element = stanza.into(); Some(elem) }, None => None })
.build() .build()
} }
} }

View file

@ -96,12 +96,12 @@ impl TryFrom<Element> for Hash {
} }
} }
impl Into<Element> for Hash { impl From<Hash> for Element {
fn into(self) -> Element { fn from(hash: Hash) -> Element {
Element::builder("hash") Element::builder("hash")
.ns(ns::HASHES) .ns(ns::HASHES)
.attr("algo", self.algo) .attr("algo", hash.algo)
.append(base64::encode(&self.hash)) .append(base64::encode(&hash.hash))
.build() .build()
} }
} }

View file

@ -78,9 +78,9 @@ impl TryFrom<Element> for IBB {
} }
} }
impl Into<Element> for IBB { impl From<IBB> for Element {
fn into(self) -> Element { fn from(ibb: IBB) -> Element {
match self { match ibb {
IBB::Open { block_size, sid, stanza } => { IBB::Open { block_size, sid, stanza } => {
Element::builder("open") Element::builder("open")
.ns(ns::IBB) .ns(ns::IBB)

View file

@ -64,16 +64,16 @@ impl TryFrom<Element> for Query {
} }
} }
impl Into<Element> for Query { impl From<Query> for Element {
fn into(self) -> Element { fn from(query: Query) -> Element {
Element::builder("query") Element::builder("query")
.ns(ns::REGISTER) .ns(ns::REGISTER)
.append(if self.registered { Some(Element::builder("registered").ns(ns::REGISTER)) } else { None }) .append(if query.registered { Some(Element::builder("registered").ns(ns::REGISTER)) } else { None })
.append(self.fields.iter().map(|(name, value)| { .append(query.fields.iter().map(|(name, value)| {
Element::builder(name.clone()).ns(ns::REGISTER).append(value.clone()) Element::builder(name.clone()).ns(ns::REGISTER).append(value.clone())
}).collect::<Vec<_>>()) }).collect::<Vec<_>>())
.append(if self.remove { Some(Element::builder("remove").ns(ns::REGISTER)) } else { None }) .append(if query.remove { Some(Element::builder("remove").ns(ns::REGISTER)) } else { None })
.append(self.form) .append(query.form)
.build() .build()
} }
} }

View file

@ -33,11 +33,11 @@ impl TryFrom<Element> for Idle {
} }
} }
impl Into<Element> for Idle { impl From<Idle> for Element {
fn into(self) -> Element { fn from(idle: Idle) -> Element {
Element::builder("idle") Element::builder("idle")
.ns(ns::IDLE) .ns(ns::IDLE)
.attr("since", self.since.to_rfc3339()) .attr("since", idle.since.to_rfc3339())
.build() .build()
} }
} }

View file

@ -83,9 +83,9 @@ impl TryFrom<Element> for IqGetPayload {
} }
} }
impl Into<Element> for IqGetPayload { impl From<IqGetPayload> for Element {
fn into(self) -> Element { fn from(payload: IqGetPayload) -> Element {
match self { match payload {
IqGetPayload::Roster(roster) => roster.into(), IqGetPayload::Roster(roster) => roster.into(),
IqGetPayload::DiscoInfo(disco) => disco.into(), IqGetPayload::DiscoInfo(disco) => disco.into(),
IqGetPayload::Ping(ping) => ping.into(), IqGetPayload::Ping(ping) => ping.into(),
@ -122,9 +122,9 @@ impl TryFrom<Element> for IqSetPayload {
} }
} }
impl Into<Element> for IqSetPayload { impl From<IqSetPayload> for Element {
fn into(self) -> Element { fn from(payload: IqSetPayload) -> Element {
match self { match payload {
IqSetPayload::Roster(roster) => roster.into(), IqSetPayload::Roster(roster) => roster.into(),
IqSetPayload::IBB(ibb) => ibb.into(), IqSetPayload::IBB(ibb) => ibb.into(),
IqSetPayload::Jingle(jingle) => jingle.into(), IqSetPayload::Jingle(jingle) => jingle.into(),
@ -157,9 +157,9 @@ impl TryFrom<Element> for IqResultPayload {
} }
} }
impl Into<Element> for IqResultPayload { impl From<IqResultPayload> for Element {
fn into(self) -> Element { fn from(payload: IqResultPayload) -> Element {
match self { match payload {
IqResultPayload::Roster(roster) => roster.into(), IqResultPayload::Roster(roster) => roster.into(),
IqResultPayload::DiscoInfo(disco) => disco.into(), IqResultPayload::DiscoInfo(disco) => disco.into(),
IqResultPayload::MamQuery(query) => query.into(), IqResultPayload::MamQuery(query) => query.into(),
@ -267,16 +267,16 @@ impl TryFrom<Element> for Iq {
} }
} }
impl Into<Element> for Iq { impl From<Iq> for Element {
fn into(self) -> Element { fn from(iq: Iq) -> Element {
let mut stanza = Element::builder("iq") let mut stanza = Element::builder("iq")
.ns(ns::JABBER_CLIENT) .ns(ns::JABBER_CLIENT)
.attr("from", self.from.and_then(|value| Some(String::from(value)))) .attr("from", iq.from.and_then(|value| Some(String::from(value))))
.attr("to", self.to.and_then(|value| Some(String::from(value)))) .attr("to", iq.to.and_then(|value| Some(String::from(value))))
.attr("id", self.id) .attr("id", iq.id)
.attr("type", &self.payload) .attr("type", &iq.payload)
.build(); .build();
let elem = match self.payload { let elem = match iq.payload {
IqType::Get(elem) IqType::Get(elem)
| IqType::Set(elem) | IqType::Set(elem)
| IqType::Result(Some(elem)) => elem, | IqType::Result(Some(elem)) => elem,

View file

@ -95,17 +95,17 @@ impl TryFrom<Element> for Content {
} }
} }
impl Into<Element> for Content { impl From<Content> for Element {
fn into(self) -> Element { fn from(content: Content) -> Element {
Element::builder("content") Element::builder("content")
.ns(ns::JINGLE) .ns(ns::JINGLE)
.attr("creator", self.creator) .attr("creator", content.creator)
.attr("disposition", self.disposition) .attr("disposition", content.disposition)
.attr("name", self.name) .attr("name", content.name)
.attr("senders", self.senders) .attr("senders", content.senders)
.append(self.description) .append(content.description)
.append(self.transport) .append(content.transport)
.append(self.security) .append(content.security)
.build() .build()
} }
} }
@ -165,9 +165,9 @@ impl FromStr for Reason {
} }
} }
impl Into<Element> for Reason { impl From<Reason> for Element {
fn into(self) -> Element { fn from(reason: Reason) -> Element {
Element::builder(match self { Element::builder(match reason {
Reason::AlternativeSession => "alternative-session", Reason::AlternativeSession => "alternative-session",
Reason::Busy => "busy", Reason::Busy => "busy",
Reason::Cancel => "cancel", Reason::Cancel => "cancel",
@ -231,12 +231,11 @@ impl TryFrom<Element> for ReasonElement {
} }
} }
impl Into<Element> for ReasonElement { impl From<ReasonElement> for Element {
fn into(self) -> Element { fn from(reason: ReasonElement) -> Element {
let reason: Element = self.reason.into();
Element::builder("reason") Element::builder("reason")
.append(reason) .append(Element::from(reason.reason))
.append(self.text) .append(reason.text)
.build() .build()
} }
} }
@ -297,16 +296,16 @@ impl TryFrom<Element> for Jingle {
} }
} }
impl Into<Element> for Jingle { impl From<Jingle> for Element {
fn into(self) -> Element { fn from(jingle: Jingle) -> Element {
Element::builder("jingle") Element::builder("jingle")
.ns(ns::JINGLE) .ns(ns::JINGLE)
.attr("action", self.action) .attr("action", jingle.action)
.attr("initiator", match self.initiator { Some(initiator) => Some(String::from(initiator)), None => None }) .attr("initiator", match jingle.initiator { Some(initiator) => Some(String::from(initiator)), None => None })
.attr("responder", match self.responder { Some(responder) => Some(String::from(responder)), None => None }) .attr("responder", match jingle.responder { Some(responder) => Some(String::from(responder)), None => None })
.attr("sid", self.sid) .attr("sid", jingle.sid)
.append(self.contents) .append(jingle.contents)
.append(self.reason) .append(jingle.reason)
.build() .build()
} }
} }

View file

@ -172,57 +172,57 @@ impl TryFrom<Element> for Description {
} }
} }
impl Into<Element> for File { impl From<File> for Element {
fn into(self) -> Element { fn from(file: File) -> Element {
let mut root = Element::builder("file") let mut root = Element::builder("file")
.ns(ns::JINGLE_FT) .ns(ns::JINGLE_FT)
.build(); .build();
if let Some(date) = self.date { if let Some(date) = file.date {
root.append_child(Element::builder("date") root.append_child(Element::builder("date")
.ns(ns::JINGLE_FT) .ns(ns::JINGLE_FT)
.append(date.to_rfc3339()) .append(date.to_rfc3339())
.build()); .build());
} }
if let Some(media_type) = self.media_type { if let Some(media_type) = file.media_type {
root.append_child(Element::builder("media-type") root.append_child(Element::builder("media-type")
.ns(ns::JINGLE_FT) .ns(ns::JINGLE_FT)
.append(media_type) .append(media_type)
.build()); .build());
} }
if let Some(name) = self.name { if let Some(name) = file.name {
root.append_child(Element::builder("name") root.append_child(Element::builder("name")
.ns(ns::JINGLE_FT) .ns(ns::JINGLE_FT)
.append(name) .append(name)
.build()); .build());
} }
if let Some(desc) = self.desc { if let Some(desc) = file.desc {
root.append_child(Element::builder("desc") root.append_child(Element::builder("desc")
.ns(ns::JINGLE_FT) .ns(ns::JINGLE_FT)
.append(desc) .append(desc)
.build()); .build());
} }
if let Some(size) = self.size { if let Some(size) = file.size {
root.append_child(Element::builder("size") root.append_child(Element::builder("size")
.ns(ns::JINGLE_FT) .ns(ns::JINGLE_FT)
.append(format!("{}", size)) .append(format!("{}", size))
.build()); .build());
} }
if let Some(range) = self.range { if let Some(range) = file.range {
root.append_child(Element::builder("range") root.append_child(Element::builder("range")
.ns(ns::JINGLE_FT) .ns(ns::JINGLE_FT)
.append(range) .append(range)
.build()); .build());
} }
for hash in self.hashes { for hash in file.hashes {
root.append_child(hash.into()); root.append_child(hash.into());
} }
root root
} }
} }
impl Into<Element> for Description { impl From<Description> for Element {
fn into(self) -> Element { fn from(description: Description) -> Element {
let file: Element = self.file.into(); let file: Element = description.file.into();
Element::builder("description") Element::builder("description")
.ns(ns::JINGLE_FT) .ns(ns::JINGLE_FT)
.append(file) .append(file)

View file

@ -42,13 +42,13 @@ impl TryFrom<Element> for Transport {
} }
} }
impl Into<Element> for Transport { impl From<Transport> for Element {
fn into(self) -> Element { fn from(transport: Transport) -> Element {
Element::builder("transport") Element::builder("transport")
.ns(ns::JINGLE_IBB) .ns(ns::JINGLE_IBB)
.attr("block-size", self.block_size) .attr("block-size", transport.block_size)
.attr("sid", self.sid) .attr("sid", transport.sid)
.attr("stanza", self.stanza) .attr("stanza", transport.stanza)
.build() .build()
} }
} }

View file

@ -40,16 +40,16 @@ pub struct Candidate {
pub type_: Type, pub type_: Type,
} }
impl Into<Element> for Candidate { impl From<Candidate> for Element {
fn into(self) -> Element { fn from(candidate: Candidate) -> Element {
Element::builder("candidate") Element::builder("candidate")
.ns(ns::JINGLE_S5B) .ns(ns::JINGLE_S5B)
.attr("cid", self.cid) .attr("cid", candidate.cid)
.attr("host", self.host) .attr("host", candidate.host)
.attr("jid", String::from(self.jid)) .attr("jid", String::from(candidate.jid))
.attr("port", self.port) .attr("port", candidate.port)
.attr("priority", self.priority) .attr("priority", candidate.priority)
.attr("type", self.type_) .attr("type", candidate.type_)
.build() .build()
} }
} }
@ -137,14 +137,14 @@ impl TryFrom<Element> for Transport {
} }
} }
impl Into<Element> for Transport { impl From<Transport> for Element {
fn into(self) -> Element { fn from(transport: Transport) -> Element {
Element::builder("transport") Element::builder("transport")
.ns(ns::JINGLE_S5B) .ns(ns::JINGLE_S5B)
.attr("sid", self.sid) .attr("sid", transport.sid)
.attr("dstaddr", self.dstaddr) .attr("dstaddr", transport.dstaddr)
.attr("mode", self.mode) .attr("mode", transport.mode)
.append(match self.payload { .append(match transport.payload {
TransportPayload::Candidates(mut candidates) => { TransportPayload::Candidates(mut candidates) => {
candidates.drain(..) candidates.drain(..)
.map(|candidate| candidate.into()) .map(|candidate| candidate.into())

View file

@ -161,52 +161,52 @@ impl TryFrom<Element> for Prefs {
} }
} }
impl Into<Element> for Query { impl From<Query> for Element {
fn into(self) -> Element { fn from(query: Query) -> Element {
Element::builder("query") Element::builder("query")
.ns(ns::MAM) .ns(ns::MAM)
.attr("queryid", self.queryid) .attr("queryid", query.queryid)
.attr("node", self.node) .attr("node", query.node)
//.append(self.form.map(|form| -> Element { form.into() })) //.append(query.form.map(|form| -> Element { form.into() }))
.append(self.set.map(|set| -> Element { set.into() })) .append(query.set.map(|set| -> Element { set.into() }))
.build() .build()
} }
} }
impl Into<Element> for Result_ { impl From<Result_> for Element {
fn into(self) -> Element { fn from(result: Result_) -> Element {
let mut elem = Element::builder("result") let mut elem = Element::builder("result")
.ns(ns::MAM) .ns(ns::MAM)
.attr("queryid", self.queryid) .attr("queryid", result.queryid)
.attr("id", self.id) .attr("id", result.id)
.build(); .build();
elem.append_child(self.forwarded.into()); elem.append_child(result.forwarded.into());
elem elem
} }
} }
impl Into<Element> for Fin { impl From<Fin> for Element {
fn into(self) -> Element { fn from(fin: Fin) -> Element {
let mut elem = Element::builder("fin") let mut elem = Element::builder("fin")
.ns(ns::MAM) .ns(ns::MAM)
.attr("complete", if self.complete { Some("true") } else { None }) .attr("complete", if fin.complete { Some("true") } else { None })
.build(); .build();
elem.append_child(self.set.into()); elem.append_child(fin.set.into());
elem elem
} }
} }
impl Into<Element> for Prefs { impl From<Prefs> for Element {
fn into(self) -> Element { fn from(prefs: Prefs) -> Element {
let mut elem = Element::builder("prefs") let mut elem = Element::builder("prefs")
.ns(ns::MAM) .ns(ns::MAM)
.attr("default", self.default_) .attr("default", prefs.default_)
.build(); .build();
if !self.always.is_empty() { if !prefs.always.is_empty() {
let mut always = Element::builder("always") let mut always = Element::builder("always")
.ns(ns::RSM) .ns(ns::RSM)
.build(); .build();
for jid in self.always { for jid in prefs.always {
always.append_child(Element::builder("jid") always.append_child(Element::builder("jid")
.ns(ns::RSM) .ns(ns::RSM)
.append(String::from(jid)) .append(String::from(jid))
@ -214,11 +214,11 @@ impl Into<Element> for Prefs {
} }
elem.append_child(always); elem.append_child(always);
} }
if !self.never.is_empty() { if !prefs.never.is_empty() {
let mut never = Element::builder("never") let mut never = Element::builder("never")
.ns(ns::RSM) .ns(ns::RSM)
.build(); .build();
for jid in self.never { for jid in prefs.never {
never.append_child(Element::builder("jid") never.append_child(Element::builder("jid")
.ns(ns::RSM) .ns(ns::RSM)
.append(String::from(jid)) .append(String::from(jid))

View file

@ -84,9 +84,9 @@ impl TryFrom<Element> for MessagePayload {
} }
} }
impl Into<Element> for MessagePayload { impl From<MessagePayload> for Element {
fn into(self) -> Element { fn from(payload: MessagePayload) -> Element {
match self { match payload {
MessagePayload::StanzaError(stanza_error) => stanza_error.into(), MessagePayload::StanzaError(stanza_error) => stanza_error.into(),
MessagePayload::Attention(attention) => attention.into(), MessagePayload::Attention(attention) => attention.into(),
MessagePayload::ChatState(chatstate) => chatstate.into(), MessagePayload::ChatState(chatstate) => chatstate.into(),
@ -199,37 +199,37 @@ impl TryFrom<Element> for Message {
} }
} }
impl Into<Element> for Message { impl From<Message> for Element {
fn into(self) -> Element { fn from(message: Message) -> Element {
Element::builder("message") Element::builder("message")
.ns(ns::JABBER_CLIENT) .ns(ns::JABBER_CLIENT)
.attr("from", self.from.and_then(|value| Some(String::from(value)))) .attr("from", message.from.and_then(|value| Some(String::from(value))))
.attr("to", self.to.and_then(|value| Some(String::from(value)))) .attr("to", message.to.and_then(|value| Some(String::from(value))))
.attr("id", self.id) .attr("id", message.id)
.attr("type", self.type_) .attr("type", message.type_)
.append(self.subjects.iter() .append(message.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) .append(subject)
.build() }) .build() })
.collect::<Vec<_>>()) .collect::<Vec<_>>())
.append(self.bodies.iter() .append(message.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) .append(body)
.build() }) .build() })
.collect::<Vec<_>>()) .collect::<Vec<_>>())
.append(self.payloads) .append(message.payloads)
.build() .build()
} }
} }

View file

@ -37,11 +37,11 @@ impl TryFrom<Element> for Replace {
} }
} }
impl Into<Element> for Replace { impl From<Replace> for Element {
fn into(self) -> Element { fn from(replace: Replace) -> Element {
Element::builder("replace") Element::builder("replace")
.ns(ns::MESSAGE_CORRECT) .ns(ns::MESSAGE_CORRECT)
.attr("id", self.id) .attr("id", replace.id)
.build() .build()
} }
} }

View file

@ -1,4 +1,5 @@
// Copyright (c) 2017 Maxime “pep” Buquet <pep+code@bouah.net> // Copyright (c) 2017 Maxime “pep” Buquet <pep+code@bouah.net>
// Copyright (c) 2017 Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
// //
// This Source Code Form is subject to the terms of the Mozilla Public // This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this // License, v. 2.0. If a copy of the MPL was not distributed with this
@ -44,11 +45,11 @@ impl TryFrom<Element> for Muc {
} }
} }
impl Into<Element> for Muc { impl From<Muc> for Element {
fn into(self) -> Element { fn from(muc: Muc) -> Element {
Element::builder("x") Element::builder("x")
.ns(ns::MUC) .ns(ns::MUC)
.append(self.password) .append(muc.password)
.build() .build()
} }
} }

View file

@ -1,4 +1,5 @@
// Copyright (c) 2017 Maxime “pep” Buquet <pep+code@bouah.net> // Copyright (c) 2017 Maxime “pep” Buquet <pep+code@bouah.net>
// Copyright (c) 2017 Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
// //
// This Source Code Form is subject to the terms of the Mozilla Public // This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this // License, v. 2.0. If a copy of the MPL was not distributed with this
@ -113,11 +114,11 @@ impl TryFrom<Element> for Status {
} }
} }
impl Into<Element> for Status { impl From<Status> for Element {
fn into(self) -> Element { fn from(status: Status) -> Element {
Element::builder("status") Element::builder("status")
.ns(ns::MUC_USER) .ns(ns::MUC_USER)
.attr("code", match self { .attr("code", match status {
Status::NonAnonymousRoom => 100, Status::NonAnonymousRoom => 100,
Status::AffiliationChange => 101, Status::AffiliationChange => 101,
Status::ConfigShowsUnavailableMembers => 102, Status::ConfigShowsUnavailableMembers => 102,
@ -186,11 +187,11 @@ impl TryFrom<Element> for Actor {
} }
} }
impl Into<Element> for Actor { impl From<Actor> for Element {
fn into(self) -> Element { fn from(actor: Actor) -> Element {
let elem = Element::builder("actor").ns(ns::MUC_USER); let elem = Element::builder("actor").ns(ns::MUC_USER);
(match self { (match actor {
Actor::Jid(jid) => elem.attr("jid", String::from(jid)), Actor::Jid(jid) => elem.attr("jid", String::from(jid)),
Actor::Nick(nick) => elem.attr("nick", nick), Actor::Nick(nick) => elem.attr("nick", nick),
}).build() }).build()
@ -227,11 +228,11 @@ impl TryFrom<Element> for Continue {
} }
} }
impl Into<Element> for Continue { impl From<Continue> for Element {
fn into(self) -> Element { fn from(cont: Continue) -> Element {
Element::builder("continue") Element::builder("continue")
.ns(ns::MUC_USER) .ns(ns::MUC_USER)
.attr("thread", self.thread) .attr("thread", cont.thread)
.build() .build()
} }
} }
@ -262,11 +263,11 @@ impl TryFrom<Element> for Reason {
} }
} }
impl Into<Element> for Reason { impl From<Reason> for Element {
fn into(self) -> Element { fn from(reason: Reason) -> Element {
Element::builder("reason") Element::builder("reason")
.ns(ns::MUC_USER) .ns(ns::MUC_USER)
.append(self.0) .append(reason.0)
.build() .build()
} }
} }
@ -348,20 +349,20 @@ impl TryFrom<Element> for Item {
} }
} }
impl Into<Element> for Item { impl From<Item> for Element {
fn into(self) -> Element { fn from(item: Item) -> Element {
Element::builder("item") Element::builder("item")
.ns(ns::MUC_USER) .ns(ns::MUC_USER)
.attr("affiliation", self.affiliation) .attr("affiliation", item.affiliation)
.attr("jid", match self.jid { .attr("jid", match item.jid {
Some(jid) => Some(String::from(jid)), Some(jid) => Some(String::from(jid)),
None => None, None => None,
}) })
.attr("nick", self.nick) .attr("nick", item.nick)
.attr("role", self.role) .attr("role", item.role)
.append(self.actor) .append(item.actor)
.append(self.continue_) .append(item.continue_)
.append(self.reason) .append(item.reason)
.build() .build()
} }
} }
@ -400,11 +401,11 @@ impl TryFrom<Element> for MucUser {
} }
} }
impl Into<Element> for MucUser { impl From<MucUser> for Element {
fn into(self) -> Element { fn from(muc_user: MucUser) -> Element {
Element::builder("x") Element::builder("x")
.ns(ns::MUC_USER) .ns(ns::MUC_USER)
.append(self.status) .append(muc_user.status)
.build() .build()
} }
} }

View file

@ -33,8 +33,8 @@ impl TryFrom<Element> for Ping {
} }
} }
impl Into<Element> for Ping { impl From<Ping> for Element {
fn into(self) -> Element { fn from(_: Ping) -> Element {
Element::builder("ping") Element::builder("ping")
.ns(ns::PING) .ns(ns::PING)
.build() .build()

View file

@ -117,9 +117,9 @@ impl TryFrom<Element> for PresencePayload {
} }
} }
impl Into<Element> for PresencePayload { impl From<PresencePayload> for Element {
fn into(self) -> Element { fn from(payload: PresencePayload) -> Element {
match self { match payload {
PresencePayload::StanzaError(stanza_error) => stanza_error.into(), PresencePayload::StanzaError(stanza_error) => stanza_error.into(),
PresencePayload::Muc(muc) => muc.into(), PresencePayload::Muc(muc) => muc.into(),
PresencePayload::Caps(caps) => caps.into(), PresencePayload::Caps(caps) => caps.into(),
@ -282,16 +282,16 @@ impl TryFrom<Element> for Presence {
} }
} }
impl Into<Element> for Presence { impl From<Presence> for Element {
fn into(self) -> Element { fn from(presence: Presence) -> Element {
Element::builder("presence") Element::builder("presence")
.ns(ns::JABBER_CLIENT) .ns(ns::JABBER_CLIENT)
.attr("from", self.from.and_then(|value| Some(String::from(value)))) .attr("from", presence.from.and_then(|value| Some(String::from(value))))
.attr("to", self.to.and_then(|value| Some(String::from(value)))) .attr("to", presence.to.and_then(|value| Some(String::from(value))))
.attr("id", self.id) .attr("id", presence.id)
.attr("type", self.type_) .attr("type", presence.type_)
.append(self.show) .append(presence.show)
.append(self.statuses.iter().map(|(lang, status)| { .append(presence.statuses.iter().map(|(lang, status)| {
Element::builder("status") Element::builder("status")
.attr("xml:lang", match lang.as_ref() { .attr("xml:lang", match lang.as_ref() {
"" => None, "" => None,
@ -300,8 +300,8 @@ impl Into<Element> for Presence {
.append(status) .append(status)
.build() .build()
}).collect::<Vec<_>>()) }).collect::<Vec<_>>())
.append(if self.priority == 0 { None } else { Some(format!("{}", self.priority)) }) .append(if presence.priority == 0 { None } else { Some(format!("{}", presence.priority)) })
.append(self.payloads) .append(presence.payloads)
.build() .build()
} }
} }

View file

@ -44,9 +44,9 @@ impl TryFrom<Element> for Receipt {
} }
} }
impl Into<Element> for Receipt { impl From<Receipt> for Element {
fn into(self) -> Element { fn from(receipt: Receipt) -> Element {
match self { match receipt {
Receipt::Request => Element::builder("request") Receipt::Request => Element::builder("request")
.ns(ns::RECEIPTS), .ns(ns::RECEIPTS),
Receipt::Received(id) => Element::builder("received") Receipt::Received(id) => Element::builder("received")

View file

@ -58,14 +58,14 @@ impl TryFrom<Element> for Item {
} }
} }
impl Into<Element> for Item { impl From<Item> for Element {
fn into(self) -> Element { fn from(item: Item) -> Element {
Element::builder("item") Element::builder("item")
.ns(ns::ROSTER) .ns(ns::ROSTER)
.attr("jid", String::from(self.jid)) .attr("jid", String::from(item.jid))
.attr("name", self.name) .attr("name", item.name)
.attr("subscription", self.subscription) .attr("subscription", item.subscription)
.append(self.groups.iter().map(|group| Element::builder("group").ns(ns::ROSTER).append(group)).collect::<Vec<_>>()) .append(item.groups.iter().map(|group| Element::builder("group").ns(ns::ROSTER).append(group)).collect::<Vec<_>>())
.build() .build()
} }
} }
@ -110,12 +110,12 @@ impl TryFrom<Element> for Roster {
} }
} }
impl Into<Element> for Roster { impl From<Roster> for Element {
fn into(self) -> Element { fn from(roster: Roster) -> Element {
Element::builder("query") Element::builder("query")
.ns(ns::ROSTER) .ns(ns::ROSTER)
.attr("ver", self.ver) .attr("ver", roster.ver)
.append(self.items) .append(roster.items)
.build() .build()
} }
} }

View file

@ -86,34 +86,34 @@ impl TryFrom<Element> for Set {
} }
} }
impl Into<Element> for Set { impl From<Set> for Element {
fn into(self) -> Element { fn from(set: Set) -> Element {
let mut elem = Element::builder("set") let mut elem = Element::builder("set")
.ns(ns::RSM) .ns(ns::RSM)
.build(); .build();
if self.after.is_some() { if set.after.is_some() {
elem.append_child(Element::builder("after").ns(ns::RSM).append(self.after).build()); elem.append_child(Element::builder("after").ns(ns::RSM).append(set.after).build());
} }
if self.before.is_some() { if set.before.is_some() {
elem.append_child(Element::builder("before").ns(ns::RSM).append(self.before).build()); elem.append_child(Element::builder("before").ns(ns::RSM).append(set.before).build());
} }
if self.count.is_some() { if set.count.is_some() {
elem.append_child(Element::builder("count").ns(ns::RSM).append(format!("{}", self.count.unwrap())).build()); elem.append_child(Element::builder("count").ns(ns::RSM).append(format!("{}", set.count.unwrap())).build());
} }
if self.first.is_some() { if set.first.is_some() {
elem.append_child(Element::builder("first") elem.append_child(Element::builder("first")
.ns(ns::RSM) .ns(ns::RSM)
.attr("index", self.first_index) .attr("index", set.first_index)
.append(self.first).build()); .append(set.first).build());
} }
if self.index.is_some() { if set.index.is_some() {
elem.append_child(Element::builder("index").ns(ns::RSM).append(format!("{}", self.index.unwrap())).build()); elem.append_child(Element::builder("index").ns(ns::RSM).append(format!("{}", set.index.unwrap())).build());
} }
if self.last.is_some() { if set.last.is_some() {
elem.append_child(Element::builder("last").ns(ns::RSM).append(self.last).build()); elem.append_child(Element::builder("last").ns(ns::RSM).append(set.last).build());
} }
if self.max.is_some() { if set.max.is_some() {
elem.append_child(Element::builder("max").ns(ns::RSM).append(format!("{}", self.max.unwrap())).build()); elem.append_child(Element::builder("max").ns(ns::RSM).append(format!("{}", set.max.unwrap())).build());
} }
elem elem
} }

View file

@ -172,15 +172,15 @@ impl TryFrom<Element> for StanzaError {
} }
} }
impl Into<Element> for StanzaError { impl From<StanzaError> for Element {
fn into(self) -> Element { fn from(err: StanzaError) -> Element {
let mut root = Element::builder("error") let mut root = Element::builder("error")
.ns(ns::JABBER_CLIENT) .ns(ns::JABBER_CLIENT)
.attr("type", self.type_) .attr("type", err.type_)
.attr("by", self.by.and_then(|by| Some(String::from(by)))) .attr("by", err.by.and_then(|by| Some(String::from(by))))
.append(self.defined_condition) .append(err.defined_condition)
.build(); .build();
for (lang, text) in self.texts { for (lang, text) in err.texts {
let elem = Element::builder("text") let elem = Element::builder("text")
.ns(ns::XMPP_STANZAS) .ns(ns::XMPP_STANZAS)
.attr("xml:lang", lang) .attr("xml:lang", lang)
@ -188,7 +188,7 @@ impl Into<Element> for StanzaError {
.build(); .build();
root.append_child(elem); root.append_child(elem);
} }
if let Some(other) = self.other { if let Some(other) = err.other {
root.append_child(other); root.append_child(other);
} }
root root

View file

@ -45,9 +45,9 @@ impl TryFrom<Element> for StanzaId {
} }
} }
impl Into<Element> for StanzaId { impl From<StanzaId> for Element {
fn into(self) -> Element { fn from(stanza_id: StanzaId) -> Element {
match self { match stanza_id {
StanzaId::StanzaId { id, by } => { StanzaId::StanzaId { id, by } => {
Element::builder("stanza-id") Element::builder("stanza-id")
.ns(ns::SID) .ns(ns::SID)