Replace .and_then() with .map() wherever it makes sense.

This commit is contained in:
Emmanuel Gil Peyrot 2017-07-21 01:19:34 +01:00
parent 7612c53f9a
commit 21cee25b27
6 changed files with 16 additions and 16 deletions

View file

@ -49,7 +49,7 @@ impl From<Delay> 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()

View file

@ -272,8 +272,8 @@ impl From<Iq> 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();

View file

@ -204,8 +204,8 @@ impl From<Message> 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()

View file

@ -317,8 +317,8 @@ impl From<Presence> 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)

View file

@ -31,7 +31,7 @@ impl From<Item> 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<PubSubEvent> 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<PubSubEvent> 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()

View file

@ -177,7 +177,7 @@ impl From<StanzaError> 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 {