parsers: rustfmt

Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
This commit is contained in:
Maxime “pep” Buquet 2020-04-02 22:45:20 +02:00
commit fd158d9a08
12 changed files with 114 additions and 101 deletions

View file

@ -271,18 +271,15 @@ impl From<DataForm> for Element {
form.title form.title
.map(|title| Element::builder("title", ns::DATA_FORMS).append(title)), .map(|title| Element::builder("title", ns::DATA_FORMS).append(title)),
) )
.append_all(form.instructions.map(|text| { .append_all(
Element::builder("instructions", ns::DATA_FORMS) form.instructions
.append(text) .map(|text| Element::builder("instructions", ns::DATA_FORMS).append(text)),
})) )
.append_all(form.form_type.map(|form_type| { .append_all(form.form_type.map(|form_type| {
Element::builder("field", ns::DATA_FORMS) Element::builder("field", ns::DATA_FORMS)
.attr("var", "FORM_TYPE") .attr("var", "FORM_TYPE")
.attr("type", "hidden") .attr("type", "hidden")
.append( .append(Element::builder("value", ns::DATA_FORMS).append(form_type))
Element::builder("value", ns::DATA_FORMS)
.append(form_type),
)
})) }))
.append_all(form.fields.iter().cloned().map(Element::from)) .append_all(form.fields.iter().cloned().map(Element::from))
.build() .build()

View file

@ -434,25 +434,28 @@ impl FromStr for Reason {
impl From<Reason> for Element { impl From<Reason> for Element {
fn from(reason: Reason) -> Element { fn from(reason: Reason) -> Element {
Element::builder(match reason { Element::builder(
Reason::AlternativeSession => "alternative-session", match reason {
Reason::Busy => "busy", Reason::AlternativeSession => "alternative-session",
Reason::Cancel => "cancel", Reason::Busy => "busy",
Reason::ConnectivityError => "connectivity-error", Reason::Cancel => "cancel",
Reason::Decline => "decline", Reason::ConnectivityError => "connectivity-error",
Reason::Expired => "expired", Reason::Decline => "decline",
Reason::FailedApplication => "failed-application", Reason::Expired => "expired",
Reason::FailedTransport => "failed-transport", Reason::FailedApplication => "failed-application",
Reason::GeneralError => "general-error", Reason::FailedTransport => "failed-transport",
Reason::Gone => "gone", Reason::GeneralError => "general-error",
Reason::IncompatibleParameters => "incompatible-parameters", Reason::Gone => "gone",
Reason::MediaError => "media-error", Reason::IncompatibleParameters => "incompatible-parameters",
Reason::SecurityError => "security-error", Reason::MediaError => "media-error",
Reason::Success => "success", Reason::SecurityError => "security-error",
Reason::Timeout => "timeout", Reason::Success => "success",
Reason::UnsupportedApplications => "unsupported-applications", Reason::Timeout => "timeout",
Reason::UnsupportedTransports => "unsupported-transports", Reason::UnsupportedApplications => "unsupported-applications",
}, ns::JINGLE) Reason::UnsupportedTransports => "unsupported-transports",
},
ns::JINGLE,
)
.build() .build()
} }
} }
@ -852,12 +855,10 @@ mod tests {
name: ContentId(String::from("this-is-a-stub")), name: ContentId(String::from("this-is-a-stub")),
senders: Senders::default(), senders: Senders::default(),
description: Some(Description::Unknown( description: Some(Description::Unknown(
Element::builder("description", "urn:xmpp:jingle:apps:stub:0") Element::builder("description", "urn:xmpp:jingle:apps:stub:0").build(),
.build(),
)), )),
transport: Some(Transport::Unknown( transport: Some(Transport::Unknown(
Element::builder("transport", "urn:xmpp:jingle:transports:stub:0") Element::builder("transport", "urn:xmpp:jingle:transports:stub:0").build(),
.build(),
)), )),
security: None, security: None,
}], }],

View file

@ -194,20 +194,28 @@ impl TryFrom<Element> for File {
impl From<File> for Element { impl From<File> for Element {
fn from(file: File) -> Element { fn from(file: File) -> Element {
Element::builder("file", ns::JINGLE_FT) Element::builder("file", ns::JINGLE_FT)
.append_all(file.date.map(|date| Element::builder("date", ns::JINGLE_FT).append(date)))
.append_all( .append_all(
file.media_type file.date
.map(|media_type| Element::builder("media-type", ns::JINGLE_FT).append(media_type)), .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)| { .append_all(file.descs.into_iter().map(|(lang, desc)| {
Element::builder("desc", ns::JINGLE_FT) Element::builder("desc", ns::JINGLE_FT)
.attr("xml:lang", lang) .attr("xml:lang", lang)
.append(desc.0) .append(desc.0)
})) }))
.append_all( .append_all(
file.size file.size.map(|size| {
.map(|size| Element::builder("size", ns::JINGLE_FT).append(format!("{}", size))), Element::builder("size", ns::JINGLE_FT).append(format!("{}", size))
}),
) )
.append_all(file.range) .append_all(file.range)
.append_all(file.hashes) .append_all(file.hashes)

View file

@ -85,22 +85,19 @@ impl TryFrom<Element> for JingleMI {
impl From<JingleMI> for Element { impl From<JingleMI> for Element {
fn from(jingle_mi: JingleMI) -> Element { fn from(jingle_mi: JingleMI) -> Element {
match jingle_mi { match jingle_mi {
JingleMI::Propose { sid, description } => JingleMI::Propose { sid, description } => {
Element::builder("propose", ns::JINGLE_MESSAGE) Element::builder("propose", ns::JINGLE_MESSAGE)
.attr("id", sid) .attr("id", sid)
.append(description), .append(description)
JingleMI::Retract(sid) => }
Element::builder("retract", ns::JINGLE_MESSAGE) JingleMI::Retract(sid) => {
.attr("id", sid), Element::builder("retract", ns::JINGLE_MESSAGE).attr("id", sid)
JingleMI::Accept(sid) => }
Element::builder("accept", ns::JINGLE_MESSAGE) JingleMI::Accept(sid) => Element::builder("accept", ns::JINGLE_MESSAGE).attr("id", sid),
.attr("id", sid), JingleMI::Proceed(sid) => {
JingleMI::Proceed(sid) => Element::builder("proceed", ns::JINGLE_MESSAGE).attr("id", sid)
Element::builder("proceed", ns::JINGLE_MESSAGE) }
.attr("id", sid), JingleMI::Reject(sid) => Element::builder("reject", ns::JINGLE_MESSAGE).attr("id", sid),
JingleMI::Reject(sid) =>
Element::builder("reject", ns::JINGLE_MESSAGE)
.attr("id", sid),
} }
.build() .build()
} }

View file

@ -251,17 +251,19 @@ impl From<Transport> for Element {
.into_iter() .into_iter()
.map(Element::from) .map(Element::from)
.collect::<Vec<_>>(), .collect::<Vec<_>>(),
TransportPayload::Activated(cid) => vec![ TransportPayload::Activated(cid) => {
Element::builder("activated", ns::JINGLE_S5B) vec![Element::builder("activated", ns::JINGLE_S5B)
.attr("cid", cid) .attr("cid", cid)
.build()], .build()]
TransportPayload::CandidateError => vec![ }
Element::builder("candidate-error", ns::JINGLE_S5B) TransportPayload::CandidateError => {
.build()], vec![Element::builder("candidate-error", ns::JINGLE_S5B).build()]
TransportPayload::CandidateUsed(cid) => vec![ }
Element::builder("candidate-used", ns::JINGLE_S5B) TransportPayload::CandidateUsed(cid) => {
vec![Element::builder("candidate-used", ns::JINGLE_S5B)
.attr("cid", cid) .attr("cid", cid)
.build()], .build()]
}
TransportPayload::ProxyError => { TransportPayload::ProxyError => {
vec![Element::builder("proxy-error", ns::JINGLE_S5B).build()] vec![Element::builder("proxy-error", ns::JINGLE_S5B).build()]
} }

View file

@ -167,10 +167,10 @@ fn serialise_jid_list(name: &str, jids: Vec<Jid>) -> ::std::option::IntoIter<Nod
} else { } else {
Some( Some(
Element::builder(name, ns::MAM) Element::builder(name, ns::MAM)
.append_all(jids.into_iter().map(|jid| { .append_all(
Element::builder("jid", ns::MAM) jids.into_iter()
.append(String::from(jid)) .map(|jid| Element::builder("jid", ns::MAM).append(String::from(jid))),
})) )
.into(), .into(),
) )
.into_iter() .into_iter()

View file

@ -365,11 +365,17 @@ mod tests {
let elem: Element = SetNick::new("coucou").into(); let elem: Element = SetNick::new("coucou").into();
let xml = String::from(&elem); let xml = String::from(&elem);
assert_eq!(xml, "<setnick xmlns=\"urn:xmpp:mix:core:1\"><nick>coucou</nick></setnick>"); assert_eq!(
xml,
"<setnick xmlns=\"urn:xmpp:mix:core:1\"><nick>coucou</nick></setnick>"
);
let elem: Element = Mix::new("coucou", "coucou@example").into(); let elem: Element = Mix::new("coucou", "coucou@example").into();
let xml = String::from(&elem); let xml = String::from(&elem);
assert_eq!(xml, "<mix xmlns=\"urn:xmpp:mix:core:1\"><nick>coucou</nick><jid>coucou@example</jid></mix>"); assert_eq!(
xml,
"<mix xmlns=\"urn:xmpp:mix:core:1\"><nick>coucou</nick><jid>coucou@example</jid></mix>"
);
let elem: Element = Create::new().into(); let elem: Element = Create::new().into();
let xml = String::from(&elem); let xml = String::from(&elem);

View file

@ -324,8 +324,10 @@ impl From<Presence> for Element {
.append_all(if presence.priority == 0 { .append_all(if presence.priority == 0 {
None None
} else { } else {
Some(Element::builder("priority", ns::DEFAULT_NS) Some(
.append(format!("{}", presence.priority))) Element::builder("priority", ns::DEFAULT_NS)
.append(format!("{}", presence.priority)),
)
}) })
.append_all(presence.payloads.into_iter()) .append_all(presence.payloads.into_iter())
.build() .build()

View file

@ -195,31 +195,33 @@ impl TryFrom<Element> for PubSubEvent {
impl From<PubSubEvent> for Element { impl From<PubSubEvent> for Element {
fn from(event: PubSubEvent) -> Element { fn from(event: PubSubEvent) -> Element {
let payload = match event { let payload = match event {
PubSubEvent::Configuration { node, form } => PubSubEvent::Configuration { node, form } => {
Element::builder("configuration", ns::PUBSUB_EVENT) Element::builder("configuration", ns::PUBSUB_EVENT)
.attr("node", node) .attr("node", node)
.append_all(form.map(Element::from)), .append_all(form.map(Element::from))
PubSubEvent::Delete { node, redirect } => }
Element::builder("purge", ns::PUBSUB_EVENT) PubSubEvent::Delete { node, redirect } => Element::builder("purge", ns::PUBSUB_EVENT)
.attr("node", node) .attr("node", node)
.append_all(redirect.map(|redirect| { .append_all(redirect.map(|redirect| {
Element::builder("redirect", ns::PUBSUB_EVENT) Element::builder("redirect", ns::PUBSUB_EVENT).attr("uri", redirect)
.attr("uri", redirect)
})), })),
PubSubEvent::PublishedItems { node, items } => PubSubEvent::PublishedItems { node, items } => {
Element::builder("items", ns::PUBSUB_EVENT) Element::builder("items", ns::PUBSUB_EVENT)
.attr("node", node) .attr("node", node)
.append_all(items.into_iter()), .append_all(items.into_iter())
PubSubEvent::RetractedItems { node, items } => }
PubSubEvent::RetractedItems { node, items } => {
Element::builder("items", ns::PUBSUB_EVENT) Element::builder("items", ns::PUBSUB_EVENT)
.attr("node", node) .attr("node", node)
.append_all(items.into_iter().map(|id| { .append_all(
Element::builder("retract", ns::PUBSUB_EVENT) items
.attr("id", id) .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::Purge { node } => {
Element::builder("purge", ns::PUBSUB_EVENT).attr("node", node)
}
PubSubEvent::Subscription { PubSubEvent::Subscription {
node, node,
expiry, expiry,

View file

@ -71,10 +71,10 @@ impl TryFrom<Element> for SetQuery {
impl From<SetQuery> for Element { impl From<SetQuery> for Element {
fn from(set: SetQuery) -> Element { fn from(set: SetQuery) -> Element {
Element::builder("set", ns::RSM) Element::builder("set", ns::RSM)
.append_all(set.max.map(|max| { .append_all(
Element::builder("max", ns::RSM) set.max
.append(format!("{}", max)) .map(|max| Element::builder("max", ns::RSM).append(format!("{}", max))),
})) )
.append_all( .append_all(
set.after set.after
.map(|after| Element::builder("after", ns::RSM).append(after)), .map(|after| Element::builder("after", ns::RSM).append(after)),
@ -83,10 +83,10 @@ impl From<SetQuery> for Element {
set.before set.before
.map(|before| Element::builder("before", ns::RSM).append(before)), .map(|before| Element::builder("before", ns::RSM).append(before)),
) )
.append_all(set.index.map(|index| { .append_all(
Element::builder("index", ns::RSM) set.index
.append(format!("{}", index)) .map(|index| Element::builder("index", ns::RSM).append(format!("{}", index))),
})) )
.build() .build()
} }
} }
@ -157,10 +157,10 @@ impl From<SetResult> for Element {
set.last set.last
.map(|last| Element::builder("last", ns::RSM).append(last)), .map(|last| Element::builder("last", ns::RSM).append(last)),
) )
.append_all(set.count.map(|count| { .append_all(
Element::builder("count", ns::RSM) set.count
.append(format!("{}", count)) .map(|count| Element::builder("count", ns::RSM).append(format!("{}", count))),
})) )
.build() .build()
} }
} }

View file

@ -580,8 +580,7 @@ macro_rules! generate_serialiser {
}; };
($builder:ident, $parent:ident, $elem:ident, Option, String, ($name:tt, $ns:ident)) => { ($builder:ident, $parent:ident, $elem:ident, Option, String, ($name:tt, $ns:ident)) => {
$builder.append_all($parent.$elem.map(|elem| { $builder.append_all($parent.$elem.map(|elem| {
crate::Element::builder($name, crate::ns::$ns) crate::Element::builder($name, crate::ns::$ns).append(::minidom::Node::Text(elem))
.append(::minidom::Node::Text(elem))
})) }))
}; };
($builder:ident, $parent:ident, $elem:ident, Option, $constructor:ident, ($name:tt, *)) => { ($builder:ident, $parent:ident, $elem:ident, Option, $constructor:ident, ($name:tt, *)) => {

View file

@ -454,8 +454,7 @@ impl From<Tag> for Element {
panic!("No unknown element should be present in XHTML-IM after parsing.") panic!("No unknown element should be present in XHTML-IM after parsing.")
} }
}; };
let mut builder = Element::builder(name, ns::XHTML) let mut builder = Element::builder(name, ns::XHTML).append_all(children_to_nodes(children));
.append_all(children_to_nodes(children));
for (key, value) in attrs { for (key, value) in attrs {
builder = builder.attr(key, value); builder = builder.attr(key, value);
} }