From b291e765729c5e367841de855578e38cdec43f21 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Thu, 17 Jun 2021 20:37:07 +0200 Subject: [PATCH] Use try operator for Option more --- src/client_server/alias.rs | 7 +------ src/database/rooms.rs | 14 ++------------ src/server_server.rs | 7 +------ 3 files changed, 4 insertions(+), 24 deletions(-) diff --git a/src/client_server/alias.rs b/src/client_server/alias.rs index a2ca0c82..a54bd36d 100644 --- a/src/client_server/alias.rs +++ b/src/client_server/alias.rs @@ -97,12 +97,7 @@ pub async fn get_alias_helper( .map_or_else(Vec::new, |aliases| { aliases .iter() - .filter_map(|aliases| { - aliases - .get("regex") - .and_then(|regex| regex.as_str()) - .and_then(|regex| Regex::new(regex).ok()) - }) + .filter_map(|aliases| Regex::new(aliases.get("regex")?.as_str()?).ok()) .collect::>() }); diff --git a/src/database/rooms.rs b/src/database/rooms.rs index 9e1245f2..7bb019e5 100644 --- a/src/database/rooms.rs +++ b/src/database/rooms.rs @@ -1361,12 +1361,7 @@ impl Rooms { .map_or_else(Vec::new, |users| { users .iter() - .filter_map(|users| { - users - .get("regex") - .and_then(|regex| regex.as_str()) - .and_then(|regex| Regex::new(regex).ok()) - }) + .filter_map(|users| Regex::new(users.get("regex")?.as_str()?).ok()) .collect::>() }); let aliases = namespaces @@ -1375,12 +1370,7 @@ impl Rooms { .map_or_else(Vec::new, |aliases| { aliases .iter() - .filter_map(|aliases| { - aliases - .get("regex") - .and_then(|regex| regex.as_str()) - .and_then(|regex| Regex::new(regex).ok()) - }) + .filter_map(|aliases| Regex::new(aliases.get("regex")?.as_str()?).ok()) .collect::>() }); let rooms = namespaces diff --git a/src/server_server.rs b/src/server_server.rs index f34633ac..6d074ec6 100644 --- a/src/server_server.rs +++ b/src/server_server.rs @@ -1691,12 +1691,7 @@ pub(crate) fn append_incoming_pdu( .map_or_else(Vec::new, |users| { users .iter() - .filter_map(|users| { - users - .get("regex") - .and_then(|regex| regex.as_str()) - .and_then(|regex| Regex::new(regex).ok()) - }) + .filter_map(|users| Regex::new(users.get("regex")?.as_str()?).ok()) .collect::>() }); let aliases = namespaces