From fd158d9a08885ccb087974702853ffb85d11510b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maxime=20=E2=80=9Cpep=E2=80=9D=20Buquet?= Date: Thu, 2 Apr 2020 22:45:20 +0200 Subject: [PATCH] parsers: rustfmt MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Maxime “pep” Buquet --- xmpp-parsers/src/data_forms.rs | 13 ++++----- xmpp-parsers/src/jingle.rs | 47 +++++++++++++++--------------- xmpp-parsers/src/jingle_ft.rs | 20 +++++++++---- xmpp-parsers/src/jingle_message.rs | 27 ++++++++--------- xmpp-parsers/src/jingle_s5b.rs | 20 +++++++------ xmpp-parsers/src/mam.rs | 8 ++--- xmpp-parsers/src/mix.rs | 10 +++++-- xmpp-parsers/src/presence.rs | 6 ++-- xmpp-parsers/src/pubsub/event.rs | 34 +++++++++++---------- xmpp-parsers/src/rsm.rs | 24 +++++++-------- xmpp-parsers/src/util/macros.rs | 3 +- xmpp-parsers/src/xhtml.rs | 3 +- 12 files changed, 114 insertions(+), 101 deletions(-) diff --git a/xmpp-parsers/src/data_forms.rs b/xmpp-parsers/src/data_forms.rs index ab8902d5..11603b3e 100644 --- a/xmpp-parsers/src/data_forms.rs +++ b/xmpp-parsers/src/data_forms.rs @@ -271,18 +271,15 @@ impl From for Element { form.title .map(|title| Element::builder("title", ns::DATA_FORMS).append(title)), ) - .append_all(form.instructions.map(|text| { - Element::builder("instructions", ns::DATA_FORMS) - .append(text) - })) + .append_all( + form.instructions + .map(|text| Element::builder("instructions", ns::DATA_FORMS).append(text)), + ) .append_all(form.form_type.map(|form_type| { Element::builder("field", ns::DATA_FORMS) .attr("var", "FORM_TYPE") .attr("type", "hidden") - .append( - Element::builder("value", ns::DATA_FORMS) - .append(form_type), - ) + .append(Element::builder("value", ns::DATA_FORMS).append(form_type)) })) .append_all(form.fields.iter().cloned().map(Element::from)) .build() diff --git a/xmpp-parsers/src/jingle.rs b/xmpp-parsers/src/jingle.rs index 13e11a20..e32110e3 100644 --- a/xmpp-parsers/src/jingle.rs +++ b/xmpp-parsers/src/jingle.rs @@ -434,25 +434,28 @@ impl FromStr for Reason { impl From for Element { fn from(reason: Reason) -> Element { - Element::builder(match reason { - Reason::AlternativeSession => "alternative-session", - Reason::Busy => "busy", - Reason::Cancel => "cancel", - Reason::ConnectivityError => "connectivity-error", - Reason::Decline => "decline", - Reason::Expired => "expired", - Reason::FailedApplication => "failed-application", - Reason::FailedTransport => "failed-transport", - Reason::GeneralError => "general-error", - Reason::Gone => "gone", - Reason::IncompatibleParameters => "incompatible-parameters", - Reason::MediaError => "media-error", - Reason::SecurityError => "security-error", - Reason::Success => "success", - Reason::Timeout => "timeout", - Reason::UnsupportedApplications => "unsupported-applications", - Reason::UnsupportedTransports => "unsupported-transports", - }, ns::JINGLE) + Element::builder( + match reason { + Reason::AlternativeSession => "alternative-session", + Reason::Busy => "busy", + Reason::Cancel => "cancel", + Reason::ConnectivityError => "connectivity-error", + Reason::Decline => "decline", + Reason::Expired => "expired", + Reason::FailedApplication => "failed-application", + Reason::FailedTransport => "failed-transport", + Reason::GeneralError => "general-error", + Reason::Gone => "gone", + Reason::IncompatibleParameters => "incompatible-parameters", + Reason::MediaError => "media-error", + Reason::SecurityError => "security-error", + Reason::Success => "success", + Reason::Timeout => "timeout", + Reason::UnsupportedApplications => "unsupported-applications", + Reason::UnsupportedTransports => "unsupported-transports", + }, + ns::JINGLE, + ) .build() } } @@ -852,12 +855,10 @@ mod tests { name: ContentId(String::from("this-is-a-stub")), senders: Senders::default(), description: Some(Description::Unknown( - Element::builder("description", "urn:xmpp:jingle:apps:stub:0") - .build(), + Element::builder("description", "urn:xmpp:jingle:apps:stub:0").build(), )), transport: Some(Transport::Unknown( - Element::builder("transport", "urn:xmpp:jingle:transports:stub:0") - .build(), + Element::builder("transport", "urn:xmpp:jingle:transports:stub:0").build(), )), security: None, }], diff --git a/xmpp-parsers/src/jingle_ft.rs b/xmpp-parsers/src/jingle_ft.rs index 3ced63ce..85ab5ec6 100644 --- a/xmpp-parsers/src/jingle_ft.rs +++ b/xmpp-parsers/src/jingle_ft.rs @@ -194,20 +194,28 @@ impl TryFrom for File { impl From for Element { fn from(file: File) -> Element { Element::builder("file", ns::JINGLE_FT) - .append_all(file.date.map(|date| Element::builder("date", ns::JINGLE_FT).append(date))) .append_all( - file.media_type - .map(|media_type| Element::builder("media-type", ns::JINGLE_FT).append(media_type)), + file.date + .map(|date| Element::builder("date", ns::JINGLE_FT).append(date)), + ) + .append_all( + file.media_type.map(|media_type| { + Element::builder("media-type", ns::JINGLE_FT).append(media_type) + }), + ) + .append_all( + file.name + .map(|name| Element::builder("name", ns::JINGLE_FT).append(name)), ) - .append_all(file.name.map(|name| Element::builder("name", ns::JINGLE_FT).append(name))) .append_all(file.descs.into_iter().map(|(lang, desc)| { Element::builder("desc", ns::JINGLE_FT) .attr("xml:lang", lang) .append(desc.0) })) .append_all( - file.size - .map(|size| Element::builder("size", ns::JINGLE_FT).append(format!("{}", size))), + file.size.map(|size| { + Element::builder("size", ns::JINGLE_FT).append(format!("{}", size)) + }), ) .append_all(file.range) .append_all(file.hashes) diff --git a/xmpp-parsers/src/jingle_message.rs b/xmpp-parsers/src/jingle_message.rs index a703adaa..52caa4e4 100644 --- a/xmpp-parsers/src/jingle_message.rs +++ b/xmpp-parsers/src/jingle_message.rs @@ -85,22 +85,19 @@ impl TryFrom for JingleMI { impl From for Element { fn from(jingle_mi: JingleMI) -> Element { match jingle_mi { - JingleMI::Propose { sid, description } => + JingleMI::Propose { sid, description } => { Element::builder("propose", ns::JINGLE_MESSAGE) - .attr("id", sid) - .append(description), - JingleMI::Retract(sid) => - Element::builder("retract", ns::JINGLE_MESSAGE) - .attr("id", sid), - JingleMI::Accept(sid) => - Element::builder("accept", ns::JINGLE_MESSAGE) - .attr("id", sid), - JingleMI::Proceed(sid) => - Element::builder("proceed", ns::JINGLE_MESSAGE) - .attr("id", sid), - JingleMI::Reject(sid) => - Element::builder("reject", ns::JINGLE_MESSAGE) - .attr("id", sid), + .attr("id", sid) + .append(description) + } + JingleMI::Retract(sid) => { + Element::builder("retract", ns::JINGLE_MESSAGE).attr("id", sid) + } + JingleMI::Accept(sid) => Element::builder("accept", ns::JINGLE_MESSAGE).attr("id", sid), + JingleMI::Proceed(sid) => { + Element::builder("proceed", ns::JINGLE_MESSAGE).attr("id", sid) + } + JingleMI::Reject(sid) => Element::builder("reject", ns::JINGLE_MESSAGE).attr("id", sid), } .build() } diff --git a/xmpp-parsers/src/jingle_s5b.rs b/xmpp-parsers/src/jingle_s5b.rs index 83cc45b1..7c45c0cb 100644 --- a/xmpp-parsers/src/jingle_s5b.rs +++ b/xmpp-parsers/src/jingle_s5b.rs @@ -251,17 +251,19 @@ impl From for Element { .into_iter() .map(Element::from) .collect::>(), - TransportPayload::Activated(cid) => vec![ - Element::builder("activated", ns::JINGLE_S5B) + TransportPayload::Activated(cid) => { + vec![Element::builder("activated", ns::JINGLE_S5B) .attr("cid", cid) - .build()], - TransportPayload::CandidateError => vec![ - Element::builder("candidate-error", ns::JINGLE_S5B) - .build()], - TransportPayload::CandidateUsed(cid) => vec![ - Element::builder("candidate-used", ns::JINGLE_S5B) + .build()] + } + TransportPayload::CandidateError => { + vec![Element::builder("candidate-error", ns::JINGLE_S5B).build()] + } + TransportPayload::CandidateUsed(cid) => { + vec![Element::builder("candidate-used", ns::JINGLE_S5B) .attr("cid", cid) - .build()], + .build()] + } TransportPayload::ProxyError => { vec![Element::builder("proxy-error", ns::JINGLE_S5B).build()] } diff --git a/xmpp-parsers/src/mam.rs b/xmpp-parsers/src/mam.rs index 550e9341..71212ac0 100644 --- a/xmpp-parsers/src/mam.rs +++ b/xmpp-parsers/src/mam.rs @@ -167,10 +167,10 @@ fn serialise_jid_list(name: &str, jids: Vec) -> ::std::option::IntoItercoucou"); + assert_eq!( + xml, + "coucou" + ); let elem: Element = Mix::new("coucou", "coucou@example").into(); let xml = String::from(&elem); - assert_eq!(xml, "coucoucoucou@example"); + assert_eq!( + xml, + "coucoucoucou@example" + ); let elem: Element = Create::new().into(); let xml = String::from(&elem); diff --git a/xmpp-parsers/src/presence.rs b/xmpp-parsers/src/presence.rs index 745e7b19..2d70714a 100644 --- a/xmpp-parsers/src/presence.rs +++ b/xmpp-parsers/src/presence.rs @@ -324,8 +324,10 @@ impl From for Element { .append_all(if presence.priority == 0 { None } else { - Some(Element::builder("priority", ns::DEFAULT_NS) - .append(format!("{}", presence.priority))) + Some( + Element::builder("priority", ns::DEFAULT_NS) + .append(format!("{}", presence.priority)), + ) }) .append_all(presence.payloads.into_iter()) .build() diff --git a/xmpp-parsers/src/pubsub/event.rs b/xmpp-parsers/src/pubsub/event.rs index 9637517c..54f3c2b3 100644 --- a/xmpp-parsers/src/pubsub/event.rs +++ b/xmpp-parsers/src/pubsub/event.rs @@ -195,31 +195,33 @@ impl TryFrom for PubSubEvent { impl From for Element { fn from(event: PubSubEvent) -> Element { let payload = match event { - PubSubEvent::Configuration { node, form } => + PubSubEvent::Configuration { node, form } => { Element::builder("configuration", ns::PUBSUB_EVENT) .attr("node", node) - .append_all(form.map(Element::from)), - PubSubEvent::Delete { node, redirect } => - Element::builder("purge", ns::PUBSUB_EVENT) + .append_all(form.map(Element::from)) + } + PubSubEvent::Delete { node, redirect } => Element::builder("purge", ns::PUBSUB_EVENT) .attr("node", node) .append_all(redirect.map(|redirect| { - Element::builder("redirect", ns::PUBSUB_EVENT) - .attr("uri", redirect) + Element::builder("redirect", ns::PUBSUB_EVENT).attr("uri", redirect) })), - PubSubEvent::PublishedItems { node, items } => + PubSubEvent::PublishedItems { node, items } => { Element::builder("items", ns::PUBSUB_EVENT) .attr("node", node) - .append_all(items.into_iter()), - PubSubEvent::RetractedItems { node, items } => + .append_all(items.into_iter()) + } + PubSubEvent::RetractedItems { node, items } => { Element::builder("items", ns::PUBSUB_EVENT) .attr("node", node) - .append_all(items.into_iter().map(|id| { - Element::builder("retract", ns::PUBSUB_EVENT) - .attr("id", id) - })), - PubSubEvent::Purge { node } => - Element::builder("purge", ns::PUBSUB_EVENT) - .attr("node", node), + .append_all( + items + .into_iter() + .map(|id| Element::builder("retract", ns::PUBSUB_EVENT).attr("id", id)), + ) + } + PubSubEvent::Purge { node } => { + Element::builder("purge", ns::PUBSUB_EVENT).attr("node", node) + } PubSubEvent::Subscription { node, expiry, diff --git a/xmpp-parsers/src/rsm.rs b/xmpp-parsers/src/rsm.rs index 85be64bd..4efb8bcf 100644 --- a/xmpp-parsers/src/rsm.rs +++ b/xmpp-parsers/src/rsm.rs @@ -71,10 +71,10 @@ impl TryFrom for SetQuery { impl From for Element { fn from(set: SetQuery) -> Element { Element::builder("set", ns::RSM) - .append_all(set.max.map(|max| { - Element::builder("max", ns::RSM) - .append(format!("{}", max)) - })) + .append_all( + set.max + .map(|max| Element::builder("max", ns::RSM).append(format!("{}", max))), + ) .append_all( set.after .map(|after| Element::builder("after", ns::RSM).append(after)), @@ -83,10 +83,10 @@ impl From for Element { set.before .map(|before| Element::builder("before", ns::RSM).append(before)), ) - .append_all(set.index.map(|index| { - Element::builder("index", ns::RSM) - .append(format!("{}", index)) - })) + .append_all( + set.index + .map(|index| Element::builder("index", ns::RSM).append(format!("{}", index))), + ) .build() } } @@ -157,10 +157,10 @@ impl From for Element { set.last .map(|last| Element::builder("last", ns::RSM).append(last)), ) - .append_all(set.count.map(|count| { - Element::builder("count", ns::RSM) - .append(format!("{}", count)) - })) + .append_all( + set.count + .map(|count| Element::builder("count", ns::RSM).append(format!("{}", count))), + ) .build() } } diff --git a/xmpp-parsers/src/util/macros.rs b/xmpp-parsers/src/util/macros.rs index 78020ad8..16d2c406 100644 --- a/xmpp-parsers/src/util/macros.rs +++ b/xmpp-parsers/src/util/macros.rs @@ -580,8 +580,7 @@ macro_rules! generate_serialiser { }; ($builder:ident, $parent:ident, $elem:ident, Option, String, ($name:tt, $ns:ident)) => { $builder.append_all($parent.$elem.map(|elem| { - crate::Element::builder($name, crate::ns::$ns) - .append(::minidom::Node::Text(elem)) + crate::Element::builder($name, crate::ns::$ns).append(::minidom::Node::Text(elem)) })) }; ($builder:ident, $parent:ident, $elem:ident, Option, $constructor:ident, ($name:tt, *)) => { diff --git a/xmpp-parsers/src/xhtml.rs b/xmpp-parsers/src/xhtml.rs index be8cecb0..29aea95b 100644 --- a/xmpp-parsers/src/xhtml.rs +++ b/xmpp-parsers/src/xhtml.rs @@ -454,8 +454,7 @@ impl From for Element { panic!("No unknown element should be present in XHTML-IM after parsing.") } }; - let mut builder = Element::builder(name, ns::XHTML) - .append_all(children_to_nodes(children)); + let mut builder = Element::builder(name, ns::XHTML).append_all(children_to_nodes(children)); for (key, value) in attrs { builder = builder.attr(key, value); }