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 ab8902d5693aa3aa3632e24207b5b8b2aa494213..11603b3e67b689ac7f27fb41ffed0e7eb50acea8 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 13e11a2015884ebc1e3d7964263c46fcb5aa5d7e..e32110e3eff90e738819cf8c2c682b4a51650c26 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 3ced63cece3588fc5a5dd060a994eca55a9ef284..85ab5ec6589a7621c69054690bf4143405e95d81 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 a703adaa46a818795fce386ab1d82746ba75d22b..52caa4e41e1bb6cb9f20cbb48814d125cdf25d13 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 83cc45b1ba4508d9263d102e8e2d3e38711e05a8..7c45c0cbc8955208bfbea5d1a5f6dbcc5dec66dd 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 550e9341b118ed5c1e41cb4c6e008396d1f76114..71212ac04a300d56d0e9b2ef1528f4fe626d5765 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 745e7b19e3fb4f87eb52335177fac2c43c79a0d5..2d70714a8712890db5f7ab23de6faf704e1a15bb 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 9637517c08f609d7ab440ec32668bf9208ea7f71..54f3c2b381a8affe79f765925319f1f99ffb2430 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 85be64bddd9d0692580d2f9082bb4f28b61e48d7..4efb8bcf5bf8b41a7c3f0956fe4b889905d39762 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 78020ad877558ecfed5d21c03f7b2b864d3f1c4b..16d2c406b0c822b925a1b0a5c916ca65d9d4212d 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 be8cecb0ca0deb8b1b354033b5d5ad252e40c24a..29aea95bd4f81a7e1c56b6d2de379ad5aeff2934 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); }