From 21cee25b27e9c55025d317d66c2ac5862c11baa8 Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Fri, 21 Jul 2017 01:19:34 +0100 Subject: [PATCH] Replace .and_then() with .map() wherever it makes sense. --- src/delay.rs | 2 +- src/iq.rs | 4 ++-- src/message.rs | 4 ++-- src/presence.rs | 4 ++-- src/pubsub/event.rs | 16 ++++++++-------- src/stanza_error.rs | 2 +- 6 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/delay.rs b/src/delay.rs index b96db2bd..e5123ec2 100644 --- a/src/delay.rs +++ b/src/delay.rs @@ -49,7 +49,7 @@ impl From for Element { fn from(delay: Delay) -> Element { Element::builder("delay") .ns(ns::DELAY) - .attr("from", delay.from.and_then(|value| Some(String::from(value)))) + .attr("from", delay.from.map(String::from)) .attr("stamp", delay.stamp.to_rfc3339()) .append(delay.data) .build() diff --git a/src/iq.rs b/src/iq.rs index aab1efcb..1eae2549 100644 --- a/src/iq.rs +++ b/src/iq.rs @@ -272,8 +272,8 @@ impl From for Element { fn from(iq: Iq) -> Element { let mut stanza = Element::builder("iq") .ns(ns::JABBER_CLIENT) - .attr("from", iq.from.and_then(|value| Some(String::from(value)))) - .attr("to", iq.to.and_then(|value| Some(String::from(value)))) + .attr("from", iq.from.map(String::from)) + .attr("to", iq.to.map(String::from)) .attr("id", iq.id) .attr("type", &iq.payload) .build(); diff --git a/src/message.rs b/src/message.rs index ea560425..29234321 100644 --- a/src/message.rs +++ b/src/message.rs @@ -204,8 +204,8 @@ impl From for Element { fn from(message: Message) -> Element { Element::builder("message") .ns(ns::JABBER_CLIENT) - .attr("from", message.from.and_then(|value| Some(String::from(value)))) - .attr("to", message.to.and_then(|value| Some(String::from(value)))) + .attr("from", message.from.map(String::from)) + .attr("to", message.to.map(String::from)) .attr("id", message.id) .attr("type", message.type_) .append(message.subjects.into_iter() diff --git a/src/presence.rs b/src/presence.rs index fe970e3b..93c5cf94 100644 --- a/src/presence.rs +++ b/src/presence.rs @@ -317,8 +317,8 @@ impl From for Element { fn from(presence: Presence) -> Element { Element::builder("presence") .ns(ns::JABBER_CLIENT) - .attr("from", presence.from.and_then(|value| Some(String::from(value)))) - .attr("to", presence.to.and_then(|value| Some(String::from(value)))) + .attr("from", presence.from.map(String::from)) + .attr("to", presence.to.map(String::from)) .attr("id", presence.id) .attr("type", presence.type_) .append(presence.show) diff --git a/src/pubsub/event.rs b/src/pubsub/event.rs index ef5e994b..04519e96 100644 --- a/src/pubsub/event.rs +++ b/src/pubsub/event.rs @@ -31,7 +31,7 @@ impl From for Element { .ns(ns::PUBSUB_EVENT) .attr("id", item.id) .attr("node", item.node) - .attr("publisher", item.publisher.and_then(|publisher| Some(String::from(publisher)))) + .attr("publisher", item.publisher.map(String::from)) .append(item.payload) .build() } @@ -222,11 +222,11 @@ impl From for Element { Element::builder("purge") .ns(ns::PUBSUB_EVENT) .attr("node", node) - .append(redirect.and_then(|redirect| { - Some(Element::builder("redirect") - .ns(ns::PUBSUB_EVENT) - .attr("uri", redirect) - .build()) + .append(redirect.map(|redirect| { + Element::builder("redirect") + .ns(ns::PUBSUB_EVENT) + .attr("uri", redirect) + .build() })) .build() }, @@ -260,8 +260,8 @@ impl From for Element { Element::builder("subscription") .ns(ns::PUBSUB_EVENT) .attr("node", node) - .attr("expiry", expiry.and_then(|expiry| Some(expiry.to_rfc3339()))) - .attr("jid", jid.and_then(|jid| Some(String::from(jid)))) + .attr("expiry", expiry.map(|expiry| expiry.to_rfc3339())) + .attr("jid", jid.map(String::from)) .attr("subid", subid) .attr("subscription", subscription) .build() diff --git a/src/stanza_error.rs b/src/stanza_error.rs index 4a83b8dc..3b7273b3 100644 --- a/src/stanza_error.rs +++ b/src/stanza_error.rs @@ -177,7 +177,7 @@ impl From for Element { let mut root = Element::builder("error") .ns(ns::JABBER_CLIENT) .attr("type", err.type_) - .attr("by", err.by.and_then(|by| Some(String::from(by)))) + .attr("by", err.by.map(String::from)) .append(err.defined_condition) .build(); for (lang, text) in err.texts {