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:
parent
5ec921fa6f
commit
487dbdc6de
28 changed files with 266 additions and 265 deletions
|
|
@ -32,8 +32,8 @@ impl TryFrom<Element> for Attention {
|
|||
}
|
||||
}
|
||||
|
||||
impl Into<Element> for Attention {
|
||||
fn into(self) -> Element {
|
||||
impl From<Attention> for Element {
|
||||
fn from(_: Attention) -> Element {
|
||||
Element::builder("attention")
|
||||
.ns(ns::ATTENTION)
|
||||
.build()
|
||||
|
|
|
|||
|
|
@ -45,9 +45,9 @@ impl TryFrom<Element> for ChatState {
|
|||
}
|
||||
}
|
||||
|
||||
impl Into<Element> for ChatState {
|
||||
fn into(self) -> Element {
|
||||
Element::builder(match self {
|
||||
impl From<ChatState> for Element {
|
||||
fn from(chatstate: ChatState) -> Element {
|
||||
Element::builder(match chatstate {
|
||||
ChatState::Active => "active",
|
||||
ChatState::Composing => "composing",
|
||||
ChatState::Gone => "gone",
|
||||
|
|
|
|||
10
src/delay.rs
10
src/delay.rs
|
|
@ -45,13 +45,13 @@ impl TryFrom<Element> for Delay {
|
|||
}
|
||||
}
|
||||
|
||||
impl Into<Element> for Delay {
|
||||
fn into(self) -> Element {
|
||||
impl From<Delay> for Element {
|
||||
fn from(delay: Delay) -> Element {
|
||||
Element::builder("delay")
|
||||
.ns(ns::DELAY)
|
||||
.attr("from", self.from.and_then(|value| Some(String::from(value))))
|
||||
.attr("stamp", self.stamp.to_rfc3339())
|
||||
.append(self.data)
|
||||
.attr("from", delay.from.and_then(|value| Some(String::from(value))))
|
||||
.attr("stamp", delay.stamp.to_rfc3339())
|
||||
.append(delay.data)
|
||||
.build()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
30
src/disco.rs
30
src/disco.rs
|
|
@ -53,11 +53,11 @@ pub struct Feature {
|
|||
pub var: String,
|
||||
}
|
||||
|
||||
impl Into<Element> for Feature {
|
||||
fn into(self) -> Element {
|
||||
impl From<Feature> for Element {
|
||||
fn from(feature: Feature) -> Element {
|
||||
Element::builder("feature")
|
||||
.ns(ns::DISCO_INFO)
|
||||
.attr("var", self.var)
|
||||
.attr("var", feature.var)
|
||||
.build()
|
||||
}
|
||||
}
|
||||
|
|
@ -76,14 +76,14 @@ pub struct Identity {
|
|||
pub name: Option<String>,
|
||||
}
|
||||
|
||||
impl Into<Element> for Identity {
|
||||
fn into(self) -> Element {
|
||||
impl From<Identity> for Element {
|
||||
fn from(identity: Identity) -> Element {
|
||||
Element::builder("identity")
|
||||
.ns(ns::DISCO_INFO)
|
||||
.attr("category", self.category)
|
||||
.attr("type", self.type_)
|
||||
.attr("xml:lang", self.lang)
|
||||
.attr("name", self.name)
|
||||
.attr("category", identity.category)
|
||||
.attr("type", identity.type_)
|
||||
.attr("xml:lang", identity.lang)
|
||||
.attr("name", identity.name)
|
||||
.build()
|
||||
}
|
||||
}
|
||||
|
|
@ -174,16 +174,16 @@ impl TryFrom<Element> for DiscoInfoResult {
|
|||
}
|
||||
}
|
||||
|
||||
impl Into<Element> for DiscoInfoResult {
|
||||
fn into(self) -> Element {
|
||||
for _ in self.extensions {
|
||||
impl From<DiscoInfoResult> for Element {
|
||||
fn from(disco: DiscoInfoResult) -> Element {
|
||||
for _ in disco.extensions {
|
||||
panic!("Not yet implemented!");
|
||||
}
|
||||
Element::builder("query")
|
||||
.ns(ns::DISCO_INFO)
|
||||
.attr("node", self.node)
|
||||
.append(self.identities)
|
||||
.append(self.features)
|
||||
.attr("node", disco.node)
|
||||
.append(disco.identities)
|
||||
.append(disco.features)
|
||||
.build()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -47,13 +47,13 @@ impl TryFrom<Element> for ECaps2 {
|
|||
}
|
||||
}
|
||||
|
||||
impl Into<Element> for ECaps2 {
|
||||
fn into(mut self) -> Element {
|
||||
impl From<ECaps2> for Element {
|
||||
fn from(mut ecaps2: ECaps2) -> Element {
|
||||
Element::builder("c")
|
||||
.ns(ns::ECAPS2)
|
||||
.append(self.hashes.drain(..)
|
||||
.map(|hash| hash.into())
|
||||
.collect::<Vec<Element>>())
|
||||
.append(ecaps2.hashes.drain(..)
|
||||
.map(|hash| hash.into())
|
||||
.collect::<Vec<Element>>())
|
||||
.build()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,12 +35,12 @@ impl TryFrom<Element> for ExplicitMessageEncryption {
|
|||
}
|
||||
}
|
||||
|
||||
impl Into<Element> for ExplicitMessageEncryption {
|
||||
fn into(self) -> Element {
|
||||
impl From<ExplicitMessageEncryption> for Element {
|
||||
fn from(eme: ExplicitMessageEncryption) -> Element {
|
||||
Element::builder("encryption")
|
||||
.ns(ns::EME)
|
||||
.attr("namespace", self.namespace)
|
||||
.attr("name", self.name)
|
||||
.attr("namespace", eme.namespace)
|
||||
.attr("name", eme.name)
|
||||
.build()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -48,12 +48,12 @@ impl TryFrom<Element> for Forwarded {
|
|||
}
|
||||
}
|
||||
|
||||
impl Into<Element> for Forwarded {
|
||||
fn into(self) -> Element {
|
||||
impl From<Forwarded> for Element {
|
||||
fn from(forwarded: Forwarded) -> Element {
|
||||
Element::builder("forwarded")
|
||||
.ns(ns::FORWARD)
|
||||
.append(match self.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.delay { Some(delay) => { let elem: Element = delay.into(); Some(elem) }, None => None })
|
||||
.append(match forwarded.stanza { Some(stanza) => { let elem: Element = stanza.into(); Some(elem) }, None => None })
|
||||
.build()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -96,12 +96,12 @@ impl TryFrom<Element> for Hash {
|
|||
}
|
||||
}
|
||||
|
||||
impl Into<Element> for Hash {
|
||||
fn into(self) -> Element {
|
||||
impl From<Hash> for Element {
|
||||
fn from(hash: Hash) -> Element {
|
||||
Element::builder("hash")
|
||||
.ns(ns::HASHES)
|
||||
.attr("algo", self.algo)
|
||||
.append(base64::encode(&self.hash))
|
||||
.attr("algo", hash.algo)
|
||||
.append(base64::encode(&hash.hash))
|
||||
.build()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -78,9 +78,9 @@ impl TryFrom<Element> for IBB {
|
|||
}
|
||||
}
|
||||
|
||||
impl Into<Element> for IBB {
|
||||
fn into(self) -> Element {
|
||||
match self {
|
||||
impl From<IBB> for Element {
|
||||
fn from(ibb: IBB) -> Element {
|
||||
match ibb {
|
||||
IBB::Open { block_size, sid, stanza } => {
|
||||
Element::builder("open")
|
||||
.ns(ns::IBB)
|
||||
|
|
|
|||
12
src/ibr.rs
12
src/ibr.rs
|
|
@ -64,16 +64,16 @@ impl TryFrom<Element> for Query {
|
|||
}
|
||||
}
|
||||
|
||||
impl Into<Element> for Query {
|
||||
fn into(self) -> Element {
|
||||
impl From<Query> for Element {
|
||||
fn from(query: Query) -> Element {
|
||||
Element::builder("query")
|
||||
.ns(ns::REGISTER)
|
||||
.append(if self.registered { Some(Element::builder("registered").ns(ns::REGISTER)) } else { None })
|
||||
.append(self.fields.iter().map(|(name, value)| {
|
||||
.append(if query.registered { Some(Element::builder("registered").ns(ns::REGISTER)) } else { None })
|
||||
.append(query.fields.iter().map(|(name, value)| {
|
||||
Element::builder(name.clone()).ns(ns::REGISTER).append(value.clone())
|
||||
}).collect::<Vec<_>>())
|
||||
.append(if self.remove { Some(Element::builder("remove").ns(ns::REGISTER)) } else { None })
|
||||
.append(self.form)
|
||||
.append(if query.remove { Some(Element::builder("remove").ns(ns::REGISTER)) } else { None })
|
||||
.append(query.form)
|
||||
.build()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,11 +33,11 @@ impl TryFrom<Element> for Idle {
|
|||
}
|
||||
}
|
||||
|
||||
impl Into<Element> for Idle {
|
||||
fn into(self) -> Element {
|
||||
impl From<Idle> for Element {
|
||||
fn from(idle: Idle) -> Element {
|
||||
Element::builder("idle")
|
||||
.ns(ns::IDLE)
|
||||
.attr("since", self.since.to_rfc3339())
|
||||
.attr("since", idle.since.to_rfc3339())
|
||||
.build()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
32
src/iq.rs
32
src/iq.rs
|
|
@ -83,9 +83,9 @@ impl TryFrom<Element> for IqGetPayload {
|
|||
}
|
||||
}
|
||||
|
||||
impl Into<Element> for IqGetPayload {
|
||||
fn into(self) -> Element {
|
||||
match self {
|
||||
impl From<IqGetPayload> for Element {
|
||||
fn from(payload: IqGetPayload) -> Element {
|
||||
match payload {
|
||||
IqGetPayload::Roster(roster) => roster.into(),
|
||||
IqGetPayload::DiscoInfo(disco) => disco.into(),
|
||||
IqGetPayload::Ping(ping) => ping.into(),
|
||||
|
|
@ -122,9 +122,9 @@ impl TryFrom<Element> for IqSetPayload {
|
|||
}
|
||||
}
|
||||
|
||||
impl Into<Element> for IqSetPayload {
|
||||
fn into(self) -> Element {
|
||||
match self {
|
||||
impl From<IqSetPayload> for Element {
|
||||
fn from(payload: IqSetPayload) -> Element {
|
||||
match payload {
|
||||
IqSetPayload::Roster(roster) => roster.into(),
|
||||
IqSetPayload::IBB(ibb) => ibb.into(),
|
||||
IqSetPayload::Jingle(jingle) => jingle.into(),
|
||||
|
|
@ -157,9 +157,9 @@ impl TryFrom<Element> for IqResultPayload {
|
|||
}
|
||||
}
|
||||
|
||||
impl Into<Element> for IqResultPayload {
|
||||
fn into(self) -> Element {
|
||||
match self {
|
||||
impl From<IqResultPayload> for Element {
|
||||
fn from(payload: IqResultPayload) -> Element {
|
||||
match payload {
|
||||
IqResultPayload::Roster(roster) => roster.into(),
|
||||
IqResultPayload::DiscoInfo(disco) => disco.into(),
|
||||
IqResultPayload::MamQuery(query) => query.into(),
|
||||
|
|
@ -267,16 +267,16 @@ impl TryFrom<Element> for Iq {
|
|||
}
|
||||
}
|
||||
|
||||
impl Into<Element> for Iq {
|
||||
fn into(self) -> Element {
|
||||
impl From<Iq> for Element {
|
||||
fn from(iq: Iq) -> Element {
|
||||
let mut stanza = Element::builder("iq")
|
||||
.ns(ns::JABBER_CLIENT)
|
||||
.attr("from", self.from.and_then(|value| Some(String::from(value))))
|
||||
.attr("to", self.to.and_then(|value| Some(String::from(value))))
|
||||
.attr("id", self.id)
|
||||
.attr("type", &self.payload)
|
||||
.attr("from", iq.from.and_then(|value| Some(String::from(value))))
|
||||
.attr("to", iq.to.and_then(|value| Some(String::from(value))))
|
||||
.attr("id", iq.id)
|
||||
.attr("type", &iq.payload)
|
||||
.build();
|
||||
let elem = match self.payload {
|
||||
let elem = match iq.payload {
|
||||
IqType::Get(elem)
|
||||
| IqType::Set(elem)
|
||||
| IqType::Result(Some(elem)) => elem,
|
||||
|
|
|
|||
|
|
@ -95,17 +95,17 @@ impl TryFrom<Element> for Content {
|
|||
}
|
||||
}
|
||||
|
||||
impl Into<Element> for Content {
|
||||
fn into(self) -> Element {
|
||||
impl From<Content> for Element {
|
||||
fn from(content: Content) -> Element {
|
||||
Element::builder("content")
|
||||
.ns(ns::JINGLE)
|
||||
.attr("creator", self.creator)
|
||||
.attr("disposition", self.disposition)
|
||||
.attr("name", self.name)
|
||||
.attr("senders", self.senders)
|
||||
.append(self.description)
|
||||
.append(self.transport)
|
||||
.append(self.security)
|
||||
.attr("creator", content.creator)
|
||||
.attr("disposition", content.disposition)
|
||||
.attr("name", content.name)
|
||||
.attr("senders", content.senders)
|
||||
.append(content.description)
|
||||
.append(content.transport)
|
||||
.append(content.security)
|
||||
.build()
|
||||
}
|
||||
}
|
||||
|
|
@ -165,9 +165,9 @@ impl FromStr for Reason {
|
|||
}
|
||||
}
|
||||
|
||||
impl Into<Element> for Reason {
|
||||
fn into(self) -> Element {
|
||||
Element::builder(match self {
|
||||
impl From<Reason> for Element {
|
||||
fn from(reason: Reason) -> Element {
|
||||
Element::builder(match reason {
|
||||
Reason::AlternativeSession => "alternative-session",
|
||||
Reason::Busy => "busy",
|
||||
Reason::Cancel => "cancel",
|
||||
|
|
@ -231,12 +231,11 @@ impl TryFrom<Element> for ReasonElement {
|
|||
}
|
||||
}
|
||||
|
||||
impl Into<Element> for ReasonElement {
|
||||
fn into(self) -> Element {
|
||||
let reason: Element = self.reason.into();
|
||||
impl From<ReasonElement> for Element {
|
||||
fn from(reason: ReasonElement) -> Element {
|
||||
Element::builder("reason")
|
||||
.append(reason)
|
||||
.append(self.text)
|
||||
.append(Element::from(reason.reason))
|
||||
.append(reason.text)
|
||||
.build()
|
||||
}
|
||||
}
|
||||
|
|
@ -297,16 +296,16 @@ impl TryFrom<Element> for Jingle {
|
|||
}
|
||||
}
|
||||
|
||||
impl Into<Element> for Jingle {
|
||||
fn into(self) -> Element {
|
||||
impl From<Jingle> for Element {
|
||||
fn from(jingle: Jingle) -> Element {
|
||||
Element::builder("jingle")
|
||||
.ns(ns::JINGLE)
|
||||
.attr("action", self.action)
|
||||
.attr("initiator", match self.initiator { Some(initiator) => Some(String::from(initiator)), None => None })
|
||||
.attr("responder", match self.responder { Some(responder) => Some(String::from(responder)), None => None })
|
||||
.attr("sid", self.sid)
|
||||
.append(self.contents)
|
||||
.append(self.reason)
|
||||
.attr("action", jingle.action)
|
||||
.attr("initiator", match jingle.initiator { Some(initiator) => Some(String::from(initiator)), None => None })
|
||||
.attr("responder", match jingle.responder { Some(responder) => Some(String::from(responder)), None => None })
|
||||
.attr("sid", jingle.sid)
|
||||
.append(jingle.contents)
|
||||
.append(jingle.reason)
|
||||
.build()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -172,57 +172,57 @@ impl TryFrom<Element> for Description {
|
|||
}
|
||||
}
|
||||
|
||||
impl Into<Element> for File {
|
||||
fn into(self) -> Element {
|
||||
impl From<File> for Element {
|
||||
fn from(file: File) -> Element {
|
||||
let mut root = Element::builder("file")
|
||||
.ns(ns::JINGLE_FT)
|
||||
.build();
|
||||
if let Some(date) = self.date {
|
||||
if let Some(date) = file.date {
|
||||
root.append_child(Element::builder("date")
|
||||
.ns(ns::JINGLE_FT)
|
||||
.append(date.to_rfc3339())
|
||||
.build());
|
||||
}
|
||||
if let Some(media_type) = self.media_type {
|
||||
if let Some(media_type) = file.media_type {
|
||||
root.append_child(Element::builder("media-type")
|
||||
.ns(ns::JINGLE_FT)
|
||||
.append(media_type)
|
||||
.build());
|
||||
}
|
||||
if let Some(name) = self.name {
|
||||
if let Some(name) = file.name {
|
||||
root.append_child(Element::builder("name")
|
||||
.ns(ns::JINGLE_FT)
|
||||
.append(name)
|
||||
.build());
|
||||
}
|
||||
if let Some(desc) = self.desc {
|
||||
if let Some(desc) = file.desc {
|
||||
root.append_child(Element::builder("desc")
|
||||
.ns(ns::JINGLE_FT)
|
||||
.append(desc)
|
||||
.build());
|
||||
}
|
||||
if let Some(size) = self.size {
|
||||
if let Some(size) = file.size {
|
||||
root.append_child(Element::builder("size")
|
||||
.ns(ns::JINGLE_FT)
|
||||
.append(format!("{}", size))
|
||||
.build());
|
||||
}
|
||||
if let Some(range) = self.range {
|
||||
if let Some(range) = file.range {
|
||||
root.append_child(Element::builder("range")
|
||||
.ns(ns::JINGLE_FT)
|
||||
.append(range)
|
||||
.build());
|
||||
}
|
||||
for hash in self.hashes {
|
||||
for hash in file.hashes {
|
||||
root.append_child(hash.into());
|
||||
}
|
||||
root
|
||||
}
|
||||
}
|
||||
|
||||
impl Into<Element> for Description {
|
||||
fn into(self) -> Element {
|
||||
let file: Element = self.file.into();
|
||||
impl From<Description> for Element {
|
||||
fn from(description: Description) -> Element {
|
||||
let file: Element = description.file.into();
|
||||
Element::builder("description")
|
||||
.ns(ns::JINGLE_FT)
|
||||
.append(file)
|
||||
|
|
|
|||
|
|
@ -42,13 +42,13 @@ impl TryFrom<Element> for Transport {
|
|||
}
|
||||
}
|
||||
|
||||
impl Into<Element> for Transport {
|
||||
fn into(self) -> Element {
|
||||
impl From<Transport> for Element {
|
||||
fn from(transport: Transport) -> Element {
|
||||
Element::builder("transport")
|
||||
.ns(ns::JINGLE_IBB)
|
||||
.attr("block-size", self.block_size)
|
||||
.attr("sid", self.sid)
|
||||
.attr("stanza", self.stanza)
|
||||
.attr("block-size", transport.block_size)
|
||||
.attr("sid", transport.sid)
|
||||
.attr("stanza", transport.stanza)
|
||||
.build()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -40,16 +40,16 @@ pub struct Candidate {
|
|||
pub type_: Type,
|
||||
}
|
||||
|
||||
impl Into<Element> for Candidate {
|
||||
fn into(self) -> Element {
|
||||
impl From<Candidate> for Element {
|
||||
fn from(candidate: Candidate) -> Element {
|
||||
Element::builder("candidate")
|
||||
.ns(ns::JINGLE_S5B)
|
||||
.attr("cid", self.cid)
|
||||
.attr("host", self.host)
|
||||
.attr("jid", String::from(self.jid))
|
||||
.attr("port", self.port)
|
||||
.attr("priority", self.priority)
|
||||
.attr("type", self.type_)
|
||||
.attr("cid", candidate.cid)
|
||||
.attr("host", candidate.host)
|
||||
.attr("jid", String::from(candidate.jid))
|
||||
.attr("port", candidate.port)
|
||||
.attr("priority", candidate.priority)
|
||||
.attr("type", candidate.type_)
|
||||
.build()
|
||||
}
|
||||
}
|
||||
|
|
@ -137,14 +137,14 @@ impl TryFrom<Element> for Transport {
|
|||
}
|
||||
}
|
||||
|
||||
impl Into<Element> for Transport {
|
||||
fn into(self) -> Element {
|
||||
impl From<Transport> for Element {
|
||||
fn from(transport: Transport) -> Element {
|
||||
Element::builder("transport")
|
||||
.ns(ns::JINGLE_S5B)
|
||||
.attr("sid", self.sid)
|
||||
.attr("dstaddr", self.dstaddr)
|
||||
.attr("mode", self.mode)
|
||||
.append(match self.payload {
|
||||
.attr("sid", transport.sid)
|
||||
.attr("dstaddr", transport.dstaddr)
|
||||
.attr("mode", transport.mode)
|
||||
.append(match transport.payload {
|
||||
TransportPayload::Candidates(mut candidates) => {
|
||||
candidates.drain(..)
|
||||
.map(|candidate| candidate.into())
|
||||
|
|
|
|||
44
src/mam.rs
44
src/mam.rs
|
|
@ -161,52 +161,52 @@ impl TryFrom<Element> for Prefs {
|
|||
}
|
||||
}
|
||||
|
||||
impl Into<Element> for Query {
|
||||
fn into(self) -> Element {
|
||||
impl From<Query> for Element {
|
||||
fn from(query: Query) -> Element {
|
||||
Element::builder("query")
|
||||
.ns(ns::MAM)
|
||||
.attr("queryid", self.queryid)
|
||||
.attr("node", self.node)
|
||||
//.append(self.form.map(|form| -> Element { form.into() }))
|
||||
.append(self.set.map(|set| -> Element { set.into() }))
|
||||
.attr("queryid", query.queryid)
|
||||
.attr("node", query.node)
|
||||
//.append(query.form.map(|form| -> Element { form.into() }))
|
||||
.append(query.set.map(|set| -> Element { set.into() }))
|
||||
.build()
|
||||
}
|
||||
}
|
||||
|
||||
impl Into<Element> for Result_ {
|
||||
fn into(self) -> Element {
|
||||
impl From<Result_> for Element {
|
||||
fn from(result: Result_) -> Element {
|
||||
let mut elem = Element::builder("result")
|
||||
.ns(ns::MAM)
|
||||
.attr("queryid", self.queryid)
|
||||
.attr("id", self.id)
|
||||
.attr("queryid", result.queryid)
|
||||
.attr("id", result.id)
|
||||
.build();
|
||||
elem.append_child(self.forwarded.into());
|
||||
elem.append_child(result.forwarded.into());
|
||||
elem
|
||||
}
|
||||
}
|
||||
|
||||
impl Into<Element> for Fin {
|
||||
fn into(self) -> Element {
|
||||
impl From<Fin> for Element {
|
||||
fn from(fin: Fin) -> Element {
|
||||
let mut elem = Element::builder("fin")
|
||||
.ns(ns::MAM)
|
||||
.attr("complete", if self.complete { Some("true") } else { None })
|
||||
.attr("complete", if fin.complete { Some("true") } else { None })
|
||||
.build();
|
||||
elem.append_child(self.set.into());
|
||||
elem.append_child(fin.set.into());
|
||||
elem
|
||||
}
|
||||
}
|
||||
|
||||
impl Into<Element> for Prefs {
|
||||
fn into(self) -> Element {
|
||||
impl From<Prefs> for Element {
|
||||
fn from(prefs: Prefs) -> Element {
|
||||
let mut elem = Element::builder("prefs")
|
||||
.ns(ns::MAM)
|
||||
.attr("default", self.default_)
|
||||
.attr("default", prefs.default_)
|
||||
.build();
|
||||
if !self.always.is_empty() {
|
||||
if !prefs.always.is_empty() {
|
||||
let mut always = Element::builder("always")
|
||||
.ns(ns::RSM)
|
||||
.build();
|
||||
for jid in self.always {
|
||||
for jid in prefs.always {
|
||||
always.append_child(Element::builder("jid")
|
||||
.ns(ns::RSM)
|
||||
.append(String::from(jid))
|
||||
|
|
@ -214,11 +214,11 @@ impl Into<Element> for Prefs {
|
|||
}
|
||||
elem.append_child(always);
|
||||
}
|
||||
if !self.never.is_empty() {
|
||||
if !prefs.never.is_empty() {
|
||||
let mut never = Element::builder("never")
|
||||
.ns(ns::RSM)
|
||||
.build();
|
||||
for jid in self.never {
|
||||
for jid in prefs.never {
|
||||
never.append_child(Element::builder("jid")
|
||||
.ns(ns::RSM)
|
||||
.append(String::from(jid))
|
||||
|
|
|
|||
|
|
@ -84,9 +84,9 @@ impl TryFrom<Element> for MessagePayload {
|
|||
}
|
||||
}
|
||||
|
||||
impl Into<Element> for MessagePayload {
|
||||
fn into(self) -> Element {
|
||||
match self {
|
||||
impl From<MessagePayload> for Element {
|
||||
fn from(payload: MessagePayload) -> Element {
|
||||
match payload {
|
||||
MessagePayload::StanzaError(stanza_error) => stanza_error.into(),
|
||||
MessagePayload::Attention(attention) => attention.into(),
|
||||
MessagePayload::ChatState(chatstate) => chatstate.into(),
|
||||
|
|
@ -199,37 +199,37 @@ impl TryFrom<Element> for Message {
|
|||
}
|
||||
}
|
||||
|
||||
impl Into<Element> for Message {
|
||||
fn into(self) -> Element {
|
||||
impl From<Message> for Element {
|
||||
fn from(message: Message) -> Element {
|
||||
Element::builder("message")
|
||||
.ns(ns::JABBER_CLIENT)
|
||||
.attr("from", self.from.and_then(|value| Some(String::from(value))))
|
||||
.attr("to", self.to.and_then(|value| Some(String::from(value))))
|
||||
.attr("id", self.id)
|
||||
.attr("type", self.type_)
|
||||
.append(self.subjects.iter()
|
||||
.map(|(lang, subject)| {
|
||||
Element::builder("subject")
|
||||
.ns(ns::JABBER_CLIENT)
|
||||
.attr("xml:lang", match lang.as_ref() {
|
||||
"" => None,
|
||||
lang => Some(lang),
|
||||
})
|
||||
.append(subject)
|
||||
.build() })
|
||||
.collect::<Vec<_>>())
|
||||
.append(self.bodies.iter()
|
||||
.map(|(lang, body)| {
|
||||
Element::builder("body")
|
||||
.ns(ns::JABBER_CLIENT)
|
||||
.attr("xml:lang", match lang.as_ref() {
|
||||
"" => None,
|
||||
lang => Some(lang),
|
||||
})
|
||||
.append(body)
|
||||
.build() })
|
||||
.collect::<Vec<_>>())
|
||||
.append(self.payloads)
|
||||
.attr("from", message.from.and_then(|value| Some(String::from(value))))
|
||||
.attr("to", message.to.and_then(|value| Some(String::from(value))))
|
||||
.attr("id", message.id)
|
||||
.attr("type", message.type_)
|
||||
.append(message.subjects.iter()
|
||||
.map(|(lang, subject)| {
|
||||
Element::builder("subject")
|
||||
.ns(ns::JABBER_CLIENT)
|
||||
.attr("xml:lang", match lang.as_ref() {
|
||||
"" => None,
|
||||
lang => Some(lang),
|
||||
})
|
||||
.append(subject)
|
||||
.build() })
|
||||
.collect::<Vec<_>>())
|
||||
.append(message.bodies.iter()
|
||||
.map(|(lang, body)| {
|
||||
Element::builder("body")
|
||||
.ns(ns::JABBER_CLIENT)
|
||||
.attr("xml:lang", match lang.as_ref() {
|
||||
"" => None,
|
||||
lang => Some(lang),
|
||||
})
|
||||
.append(body)
|
||||
.build() })
|
||||
.collect::<Vec<_>>())
|
||||
.append(message.payloads)
|
||||
.build()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,11 +37,11 @@ impl TryFrom<Element> for Replace {
|
|||
}
|
||||
}
|
||||
|
||||
impl Into<Element> for Replace {
|
||||
fn into(self) -> Element {
|
||||
impl From<Replace> for Element {
|
||||
fn from(replace: Replace) -> Element {
|
||||
Element::builder("replace")
|
||||
.ns(ns::MESSAGE_CORRECT)
|
||||
.attr("id", self.id)
|
||||
.attr("id", replace.id)
|
||||
.build()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
// 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
|
||||
// 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 {
|
||||
fn into(self) -> Element {
|
||||
impl From<Muc> for Element {
|
||||
fn from(muc: Muc) -> Element {
|
||||
Element::builder("x")
|
||||
.ns(ns::MUC)
|
||||
.append(self.password)
|
||||
.append(muc.password)
|
||||
.build()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
// 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
|
||||
// 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 {
|
||||
fn into(self) -> Element {
|
||||
impl From<Status> for Element {
|
||||
fn from(status: Status) -> Element {
|
||||
Element::builder("status")
|
||||
.ns(ns::MUC_USER)
|
||||
.attr("code", match self {
|
||||
.attr("code", match status {
|
||||
Status::NonAnonymousRoom => 100,
|
||||
Status::AffiliationChange => 101,
|
||||
Status::ConfigShowsUnavailableMembers => 102,
|
||||
|
|
@ -186,11 +187,11 @@ impl TryFrom<Element> for Actor {
|
|||
}
|
||||
}
|
||||
|
||||
impl Into<Element> for Actor {
|
||||
fn into(self) -> Element {
|
||||
impl From<Actor> for Element {
|
||||
fn from(actor: Actor) -> Element {
|
||||
let elem = Element::builder("actor").ns(ns::MUC_USER);
|
||||
|
||||
(match self {
|
||||
(match actor {
|
||||
Actor::Jid(jid) => elem.attr("jid", String::from(jid)),
|
||||
Actor::Nick(nick) => elem.attr("nick", nick),
|
||||
}).build()
|
||||
|
|
@ -227,11 +228,11 @@ impl TryFrom<Element> for Continue {
|
|||
}
|
||||
}
|
||||
|
||||
impl Into<Element> for Continue {
|
||||
fn into(self) -> Element {
|
||||
impl From<Continue> for Element {
|
||||
fn from(cont: Continue) -> Element {
|
||||
Element::builder("continue")
|
||||
.ns(ns::MUC_USER)
|
||||
.attr("thread", self.thread)
|
||||
.attr("thread", cont.thread)
|
||||
.build()
|
||||
}
|
||||
}
|
||||
|
|
@ -262,11 +263,11 @@ impl TryFrom<Element> for Reason {
|
|||
}
|
||||
}
|
||||
|
||||
impl Into<Element> for Reason {
|
||||
fn into(self) -> Element {
|
||||
impl From<Reason> for Element {
|
||||
fn from(reason: Reason) -> Element {
|
||||
Element::builder("reason")
|
||||
.ns(ns::MUC_USER)
|
||||
.append(self.0)
|
||||
.append(reason.0)
|
||||
.build()
|
||||
}
|
||||
}
|
||||
|
|
@ -348,20 +349,20 @@ impl TryFrom<Element> for Item {
|
|||
}
|
||||
}
|
||||
|
||||
impl Into<Element> for Item {
|
||||
fn into(self) -> Element {
|
||||
impl From<Item> for Element {
|
||||
fn from(item: Item) -> Element {
|
||||
Element::builder("item")
|
||||
.ns(ns::MUC_USER)
|
||||
.attr("affiliation", self.affiliation)
|
||||
.attr("jid", match self.jid {
|
||||
.attr("affiliation", item.affiliation)
|
||||
.attr("jid", match item.jid {
|
||||
Some(jid) => Some(String::from(jid)),
|
||||
None => None,
|
||||
})
|
||||
.attr("nick", self.nick)
|
||||
.attr("role", self.role)
|
||||
.append(self.actor)
|
||||
.append(self.continue_)
|
||||
.append(self.reason)
|
||||
.attr("nick", item.nick)
|
||||
.attr("role", item.role)
|
||||
.append(item.actor)
|
||||
.append(item.continue_)
|
||||
.append(item.reason)
|
||||
.build()
|
||||
}
|
||||
}
|
||||
|
|
@ -400,11 +401,11 @@ impl TryFrom<Element> for MucUser {
|
|||
}
|
||||
}
|
||||
|
||||
impl Into<Element> for MucUser {
|
||||
fn into(self) -> Element {
|
||||
impl From<MucUser> for Element {
|
||||
fn from(muc_user: MucUser) -> Element {
|
||||
Element::builder("x")
|
||||
.ns(ns::MUC_USER)
|
||||
.append(self.status)
|
||||
.append(muc_user.status)
|
||||
.build()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,8 +33,8 @@ impl TryFrom<Element> for Ping {
|
|||
}
|
||||
}
|
||||
|
||||
impl Into<Element> for Ping {
|
||||
fn into(self) -> Element {
|
||||
impl From<Ping> for Element {
|
||||
fn from(_: Ping) -> Element {
|
||||
Element::builder("ping")
|
||||
.ns(ns::PING)
|
||||
.build()
|
||||
|
|
|
|||
|
|
@ -117,9 +117,9 @@ impl TryFrom<Element> for PresencePayload {
|
|||
}
|
||||
}
|
||||
|
||||
impl Into<Element> for PresencePayload {
|
||||
fn into(self) -> Element {
|
||||
match self {
|
||||
impl From<PresencePayload> for Element {
|
||||
fn from(payload: PresencePayload) -> Element {
|
||||
match payload {
|
||||
PresencePayload::StanzaError(stanza_error) => stanza_error.into(),
|
||||
PresencePayload::Muc(muc) => muc.into(),
|
||||
PresencePayload::Caps(caps) => caps.into(),
|
||||
|
|
@ -282,16 +282,16 @@ impl TryFrom<Element> for Presence {
|
|||
}
|
||||
}
|
||||
|
||||
impl Into<Element> for Presence {
|
||||
fn into(self) -> Element {
|
||||
impl From<Presence> for Element {
|
||||
fn from(presence: Presence) -> Element {
|
||||
Element::builder("presence")
|
||||
.ns(ns::JABBER_CLIENT)
|
||||
.attr("from", self.from.and_then(|value| Some(String::from(value))))
|
||||
.attr("to", self.to.and_then(|value| Some(String::from(value))))
|
||||
.attr("id", self.id)
|
||||
.attr("type", self.type_)
|
||||
.append(self.show)
|
||||
.append(self.statuses.iter().map(|(lang, status)| {
|
||||
.attr("from", presence.from.and_then(|value| Some(String::from(value))))
|
||||
.attr("to", presence.to.and_then(|value| Some(String::from(value))))
|
||||
.attr("id", presence.id)
|
||||
.attr("type", presence.type_)
|
||||
.append(presence.show)
|
||||
.append(presence.statuses.iter().map(|(lang, status)| {
|
||||
Element::builder("status")
|
||||
.attr("xml:lang", match lang.as_ref() {
|
||||
"" => None,
|
||||
|
|
@ -300,8 +300,8 @@ impl Into<Element> for Presence {
|
|||
.append(status)
|
||||
.build()
|
||||
}).collect::<Vec<_>>())
|
||||
.append(if self.priority == 0 { None } else { Some(format!("{}", self.priority)) })
|
||||
.append(self.payloads)
|
||||
.append(if presence.priority == 0 { None } else { Some(format!("{}", presence.priority)) })
|
||||
.append(presence.payloads)
|
||||
.build()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -44,9 +44,9 @@ impl TryFrom<Element> for Receipt {
|
|||
}
|
||||
}
|
||||
|
||||
impl Into<Element> for Receipt {
|
||||
fn into(self) -> Element {
|
||||
match self {
|
||||
impl From<Receipt> for Element {
|
||||
fn from(receipt: Receipt) -> Element {
|
||||
match receipt {
|
||||
Receipt::Request => Element::builder("request")
|
||||
.ns(ns::RECEIPTS),
|
||||
Receipt::Received(id) => Element::builder("received")
|
||||
|
|
|
|||
|
|
@ -58,14 +58,14 @@ impl TryFrom<Element> for Item {
|
|||
}
|
||||
}
|
||||
|
||||
impl Into<Element> for Item {
|
||||
fn into(self) -> Element {
|
||||
impl From<Item> for Element {
|
||||
fn from(item: Item) -> Element {
|
||||
Element::builder("item")
|
||||
.ns(ns::ROSTER)
|
||||
.attr("jid", String::from(self.jid))
|
||||
.attr("name", self.name)
|
||||
.attr("subscription", self.subscription)
|
||||
.append(self.groups.iter().map(|group| Element::builder("group").ns(ns::ROSTER).append(group)).collect::<Vec<_>>())
|
||||
.attr("jid", String::from(item.jid))
|
||||
.attr("name", item.name)
|
||||
.attr("subscription", item.subscription)
|
||||
.append(item.groups.iter().map(|group| Element::builder("group").ns(ns::ROSTER).append(group)).collect::<Vec<_>>())
|
||||
.build()
|
||||
}
|
||||
}
|
||||
|
|
@ -110,12 +110,12 @@ impl TryFrom<Element> for Roster {
|
|||
}
|
||||
}
|
||||
|
||||
impl Into<Element> for Roster {
|
||||
fn into(self) -> Element {
|
||||
impl From<Roster> for Element {
|
||||
fn from(roster: Roster) -> Element {
|
||||
Element::builder("query")
|
||||
.ns(ns::ROSTER)
|
||||
.attr("ver", self.ver)
|
||||
.append(self.items)
|
||||
.attr("ver", roster.ver)
|
||||
.append(roster.items)
|
||||
.build()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
34
src/rsm.rs
34
src/rsm.rs
|
|
@ -86,34 +86,34 @@ impl TryFrom<Element> for Set {
|
|||
}
|
||||
}
|
||||
|
||||
impl Into<Element> for Set {
|
||||
fn into(self) -> Element {
|
||||
impl From<Set> for Element {
|
||||
fn from(set: Set) -> Element {
|
||||
let mut elem = Element::builder("set")
|
||||
.ns(ns::RSM)
|
||||
.build();
|
||||
if self.after.is_some() {
|
||||
elem.append_child(Element::builder("after").ns(ns::RSM).append(self.after).build());
|
||||
if set.after.is_some() {
|
||||
elem.append_child(Element::builder("after").ns(ns::RSM).append(set.after).build());
|
||||
}
|
||||
if self.before.is_some() {
|
||||
elem.append_child(Element::builder("before").ns(ns::RSM).append(self.before).build());
|
||||
if set.before.is_some() {
|
||||
elem.append_child(Element::builder("before").ns(ns::RSM).append(set.before).build());
|
||||
}
|
||||
if self.count.is_some() {
|
||||
elem.append_child(Element::builder("count").ns(ns::RSM).append(format!("{}", self.count.unwrap())).build());
|
||||
if set.count.is_some() {
|
||||
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")
|
||||
.ns(ns::RSM)
|
||||
.attr("index", self.first_index)
|
||||
.append(self.first).build());
|
||||
.attr("index", set.first_index)
|
||||
.append(set.first).build());
|
||||
}
|
||||
if self.index.is_some() {
|
||||
elem.append_child(Element::builder("index").ns(ns::RSM).append(format!("{}", self.index.unwrap())).build());
|
||||
if set.index.is_some() {
|
||||
elem.append_child(Element::builder("index").ns(ns::RSM).append(format!("{}", set.index.unwrap())).build());
|
||||
}
|
||||
if self.last.is_some() {
|
||||
elem.append_child(Element::builder("last").ns(ns::RSM).append(self.last).build());
|
||||
if set.last.is_some() {
|
||||
elem.append_child(Element::builder("last").ns(ns::RSM).append(set.last).build());
|
||||
}
|
||||
if self.max.is_some() {
|
||||
elem.append_child(Element::builder("max").ns(ns::RSM).append(format!("{}", self.max.unwrap())).build());
|
||||
if set.max.is_some() {
|
||||
elem.append_child(Element::builder("max").ns(ns::RSM).append(format!("{}", set.max.unwrap())).build());
|
||||
}
|
||||
elem
|
||||
}
|
||||
|
|
|
|||
|
|
@ -172,15 +172,15 @@ impl TryFrom<Element> for StanzaError {
|
|||
}
|
||||
}
|
||||
|
||||
impl Into<Element> for StanzaError {
|
||||
fn into(self) -> Element {
|
||||
impl From<StanzaError> for Element {
|
||||
fn from(err: StanzaError) -> Element {
|
||||
let mut root = Element::builder("error")
|
||||
.ns(ns::JABBER_CLIENT)
|
||||
.attr("type", self.type_)
|
||||
.attr("by", self.by.and_then(|by| Some(String::from(by))))
|
||||
.append(self.defined_condition)
|
||||
.attr("type", err.type_)
|
||||
.attr("by", err.by.and_then(|by| Some(String::from(by))))
|
||||
.append(err.defined_condition)
|
||||
.build();
|
||||
for (lang, text) in self.texts {
|
||||
for (lang, text) in err.texts {
|
||||
let elem = Element::builder("text")
|
||||
.ns(ns::XMPP_STANZAS)
|
||||
.attr("xml:lang", lang)
|
||||
|
|
@ -188,7 +188,7 @@ impl Into<Element> for StanzaError {
|
|||
.build();
|
||||
root.append_child(elem);
|
||||
}
|
||||
if let Some(other) = self.other {
|
||||
if let Some(other) = err.other {
|
||||
root.append_child(other);
|
||||
}
|
||||
root
|
||||
|
|
|
|||
|
|
@ -45,9 +45,9 @@ impl TryFrom<Element> for StanzaId {
|
|||
}
|
||||
}
|
||||
|
||||
impl Into<Element> for StanzaId {
|
||||
fn into(self) -> Element {
|
||||
match self {
|
||||
impl From<StanzaId> for Element {
|
||||
fn from(stanza_id: StanzaId) -> Element {
|
||||
match stanza_id {
|
||||
StanzaId::StanzaId { id, by } => {
|
||||
Element::builder("stanza-id")
|
||||
.ns(ns::SID)
|
||||
|
|
|
|||
Loading…
Reference in a new issue