From f3e630c064c255bd8228de50363aa6a7fc720996 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Thu, 17 Jun 2021 20:34:14 +0200 Subject: [PATCH] Fix lots of clippy lints --- src/client_server/alias.rs | 3 +- src/client_server/directory.rs | 4 +- src/client_server/membership.rs | 10 +- src/client_server/session.rs | 6 +- src/client_server/sync.rs | 15 ++- src/database/appservice.rs | 18 ++-- src/database/globals.rs | 8 +- src/database/key_backups.rs | 5 +- src/database/media.rs | 12 +-- src/database/pusher.rs | 8 +- src/database/rooms.rs | 168 +++++++++++++------------------- src/database/rooms/edus.rs | 10 +- src/database/transaction_ids.rs | 2 +- src/database/uiaa.rs | 4 +- src/database/users.rs | 31 +++--- src/server_server.rs | 13 +-- src/utils.rs | 25 +++-- 17 files changed, 140 insertions(+), 202 deletions(-) diff --git a/src/client_server/alias.rs b/src/client_server/alias.rs index 40252af2..a2ca0c82 100644 --- a/src/client_server/alias.rs +++ b/src/client_server/alias.rs @@ -97,13 +97,12 @@ pub async fn get_alias_helper( .map_or_else(Vec::new, |aliases| { aliases .iter() - .map(|aliases| { + .filter_map(|aliases| { aliases .get("regex") .and_then(|regex| regex.as_str()) .and_then(|regex| Regex::new(regex).ok()) }) - .filter_map(|o| o) .collect::>() }); diff --git a/src/client_server/directory.rs b/src/client_server/directory.rs index c41e81e4..dfef34d4 100644 --- a/src/client_server/directory.rs +++ b/src/client_server/directory.rs @@ -135,9 +135,7 @@ pub async fn get_public_rooms_filtered_helper( filter: &IncomingFilter, _network: &IncomingRoomNetwork, ) -> ConduitResult { - if let Some(other_server) = server - .clone() - .filter(|server| *server != db.globals.server_name().as_str()) + if let Some(other_server) = server.filter(|server| *server != db.globals.server_name().as_str()) { let response = db .sending diff --git a/src/client_server/membership.rs b/src/client_server/membership.rs index a3f1389a..2dfa0776 100644 --- a/src/client_server/membership.rs +++ b/src/client_server/membership.rs @@ -743,12 +743,10 @@ pub async fn invite_helper( let create_event_content = create_event .as_ref() .map(|create_event| { - Ok::<_, Error>( - serde_json::from_value::>(create_event.content.clone()) - .expect("Raw::from_value always works.") - .deserialize() - .map_err(|_| Error::bad_database("Invalid PowerLevels event in db."))?, - ) + serde_json::from_value::>(create_event.content.clone()) + .expect("Raw::from_value always works.") + .deserialize() + .map_err(|_| Error::bad_database("Invalid PowerLevels event in db.")) }) .transpose()?; diff --git a/src/client_server/session.rs b/src/client_server/session.rs index 9a75ae28..dd504f18 100644 --- a/src/client_server/session.rs +++ b/src/client_server/session.rs @@ -202,10 +202,8 @@ pub async fn logout_all_route( ) -> ConduitResult { let sender_user = body.sender_user.as_ref().expect("user is authenticated"); - for device_id in db.users.all_device_ids(sender_user) { - if let Ok(device_id) = device_id { - db.users.remove_device(&sender_user, &device_id)?; - } + for device_id in db.users.all_device_ids(sender_user).flatten() { + db.users.remove_device(&sender_user, &device_id)?; } db.flush().await?; diff --git a/src/client_server/sync.rs b/src/client_server/sync.rs index dc92fb29..1c078e91 100644 --- a/src/client_server/sync.rs +++ b/src/client_server/sync.rs @@ -146,11 +146,9 @@ pub async fn sync_events_route( let since_state = since_shortstatehash .as_ref() .map(|since_shortstatehash| { - Ok::<_, Error>( - since_shortstatehash - .map(|since_shortstatehash| db.rooms.state_full(since_shortstatehash)) - .transpose()?, - ) + since_shortstatehash + .map(|since_shortstatehash| db.rooms.state_full(since_shortstatehash)) + .transpose() }) .transpose()?; @@ -255,7 +253,7 @@ pub async fn sync_events_route( device_list_updates.extend( db.rooms .room_members(&room_id) - .filter_map(|user_id| Some(user_id.ok()?)) + .flatten() .filter(|user_id| { // Don't send key updates from the sender to the sender sender_user != user_id @@ -313,9 +311,10 @@ pub async fn sync_events_route( Ok(None) } }) - .filter_map(|u| u.ok()) // Filter out buggy users + // Filter out buggy users + .filter_map(|u| u.ok()) // Filter for possible heroes - .filter_map(|u| u) + .flatten() { if heroes.contains(&hero) || hero == sender_user.as_str() { continue; diff --git a/src/database/appservice.rs b/src/database/appservice.rs index 21b18a76..4bf3a218 100644 --- a/src/database/appservice.rs +++ b/src/database/appservice.rs @@ -34,29 +34,25 @@ impl Appservice { .get(id) .map_or_else( || { - Ok(self - .id_appserviceregistrations + self.id_appserviceregistrations .get(id.as_bytes())? .map(|bytes| { - Ok::<_, Error>(serde_yaml::from_slice(&bytes).map_err(|_| { + serde_yaml::from_slice(&bytes).map_err(|_| { Error::bad_database( "Invalid registration bytes in id_appserviceregistrations.", ) - })?) + }) }) - .transpose()?) + .transpose() }, |r| Ok(Some(r.clone())), ) } - pub fn iter_ids<'a>( - &'a self, - ) -> Result> + Send + Sync + 'a> { + pub fn iter_ids(&self) -> Result> + Send + Sync + '_> { Ok(self.id_appserviceregistrations.iter().map(|(id, _)| { - Ok(utils::string_from_bytes(&id).map_err(|_| { - Error::bad_database("Invalid id bytes in id_appserviceregistrations.") - })?) + utils::string_from_bytes(&id) + .map_err(|_| Error::bad_database("Invalid id bytes in id_appserviceregistrations.")) })) } diff --git a/src/database/globals.rs b/src/database/globals.rs index 55256443..1ce87bd2 100644 --- a/src/database/globals.rs +++ b/src/database/globals.rs @@ -171,14 +171,14 @@ impl Globals { } pub fn next_count(&self) -> Result { - Ok(utils::u64_from_bytes(&self.globals.increment(COUNTER)?) - .map_err(|_| Error::bad_database("Count has invalid bytes."))?) + utils::u64_from_bytes(&self.globals.increment(COUNTER)?) + .map_err(|_| Error::bad_database("Count has invalid bytes.")) } pub fn current_count(&self) -> Result { self.globals.get(COUNTER)?.map_or(Ok(0_u64), |bytes| { - Ok(utils::u64_from_bytes(&bytes) - .map_err(|_| Error::bad_database("Count has invalid bytes."))?) + utils::u64_from_bytes(&bytes) + .map_err(|_| Error::bad_database("Count has invalid bytes.")) }) } diff --git a/src/database/key_backups.rs b/src/database/key_backups.rs index 0685c482..2bb3b6d5 100644 --- a/src/database/key_backups.rs +++ b/src/database/key_backups.rs @@ -119,9 +119,8 @@ impl KeyBackups { self.backupid_algorithm .get(&key)? .map_or(Ok(None), |bytes| { - Ok(serde_json::from_slice(&bytes).map_err(|_| { - Error::bad_database("Algorithm in backupid_algorithm is invalid.") - })?) + serde_json::from_slice(&bytes) + .map_err(|_| Error::bad_database("Algorithm in backupid_algorithm is invalid.")) }) } diff --git a/src/database/media.rs b/src/database/media.rs index 944c5bdc..a1fe26e1 100644 --- a/src/database/media.rs +++ b/src/database/media.rs @@ -110,9 +110,9 @@ impl Media { let content_type = parts .next() .map(|bytes| { - Ok::<_, Error>(utils::string_from_bytes(bytes).map_err(|_| { + utils::string_from_bytes(bytes).map_err(|_| { Error::bad_database("Content type in mediaid_file is invalid unicode.") - })?) + }) }) .transpose()?; @@ -199,9 +199,9 @@ impl Media { let content_type = parts .next() .map(|bytes| { - Ok::<_, Error>(utils::string_from_bytes(bytes).map_err(|_| { + utils::string_from_bytes(bytes).map_err(|_| { Error::bad_database("Content type in mediaid_file is invalid unicode.") - })?) + }) }) .transpose()?; @@ -235,9 +235,9 @@ impl Media { let content_type = parts .next() .map(|bytes| { - Ok::<_, Error>(utils::string_from_bytes(bytes).map_err(|_| { + utils::string_from_bytes(bytes).map_err(|_| { Error::bad_database("Content type in mediaid_file is invalid unicode.") - })?) + }) }) .transpose()?; diff --git a/src/database/pusher.rs b/src/database/pusher.rs index 39b631dc..358c3c98 100644 --- a/src/database/pusher.rs +++ b/src/database/pusher.rs @@ -51,8 +51,8 @@ impl PushData { self.senderkey_pusher .get(senderkey)? .map(|push| { - Ok(serde_json::from_slice(&*push) - .map_err(|_| Error::bad_database("Invalid Pusher in db."))?) + serde_json::from_slice(&*push) + .map_err(|_| Error::bad_database("Invalid Pusher in db.")) }) .transpose() } @@ -64,8 +64,8 @@ impl PushData { self.senderkey_pusher .scan_prefix(prefix) .map(|(_, push)| { - Ok(serde_json::from_slice(&*push) - .map_err(|_| Error::bad_database("Invalid Pusher in db."))?) + serde_json::from_slice(&*push) + .map_err(|_| Error::bad_database("Invalid Pusher in db.")) }) .collect() } diff --git a/src/database/rooms.rs b/src/database/rooms.rs index 0820395e..9e1245f2 100644 --- a/src/database/rooms.rs +++ b/src/database/rooms.rs @@ -93,14 +93,10 @@ impl Rooms { .map(|(_, bytes)| self.shorteventid_eventid.get(&bytes).ok().flatten()) .flatten() .map(|bytes| { - Ok::<_, Error>( - EventId::try_from(utils::string_from_bytes(&bytes).map_err(|_| { - Error::bad_database("EventID in stateid_shorteventid is invalid unicode.") - })?) - .map_err(|_| { - Error::bad_database("EventId in stateid_shorteventid is invalid.") - })?, - ) + EventId::try_from(utils::string_from_bytes(&bytes).map_err(|_| { + Error::bad_database("EventID in stateid_shorteventid is invalid unicode.") + })?) + .map_err(|_| Error::bad_database("EventId in stateid_shorteventid is invalid.")) }) .filter_map(|r| r.ok()) .collect()) @@ -116,14 +112,10 @@ impl Rooms { .map(|(_, bytes)| self.shorteventid_eventid.get(&bytes).ok().flatten()) .flatten() .map(|bytes| { - Ok::<_, Error>( - EventId::try_from(utils::string_from_bytes(&bytes).map_err(|_| { - Error::bad_database("EventID in stateid_shorteventid is invalid unicode.") - })?) - .map_err(|_| { - Error::bad_database("EventId in stateid_shorteventid is invalid.") - })?, - ) + EventId::try_from(utils::string_from_bytes(&bytes).map_err(|_| { + Error::bad_database("EventID in stateid_shorteventid is invalid unicode.") + })?) + .map_err(|_| Error::bad_database("EventId in stateid_shorteventid is invalid.")) }) .filter_map(|r| r.ok()) .map(|eventid| self.get_pdu(&eventid)) @@ -168,16 +160,10 @@ impl Rooms { .map(|bytes| self.shorteventid_eventid.get(&bytes).ok().flatten()) .flatten() .map(|bytes| { - Ok::<_, Error>( - EventId::try_from(utils::string_from_bytes(&bytes).map_err(|_| { - Error::bad_database( - "EventID in stateid_shorteventid is invalid unicode.", - ) - })?) - .map_err(|_| { - Error::bad_database("EventId in stateid_shorteventid is invalid.") - })?, - ) + EventId::try_from(utils::string_from_bytes(&bytes).map_err(|_| { + Error::bad_database("EventID in stateid_shorteventid is invalid unicode.") + })?) + .map_err(|_| Error::bad_database("EventId in stateid_shorteventid is invalid.")) }) .map(|r| r.ok()) .flatten()) @@ -204,16 +190,16 @@ impl Rooms { self.eventid_shorteventid .get(event_id.as_bytes())? .map_or(Ok(None), |shorteventid| { - Ok(self - .shorteventid_shortstatehash - .get(&shorteventid)? - .map_or(Ok::<_, Error>(None), |bytes| { + self.shorteventid_shortstatehash.get(&shorteventid)?.map_or( + Ok::<_, Error>(None), + |bytes| { Ok(Some(utils::u64_from_bytes(&bytes).map_err(|_| { Error::bad_database( "Invalid shortstatehash bytes in shorteventid_shortstatehash", ) })?)) - })?) + }, + ) }) } @@ -485,7 +471,7 @@ impl Rooms { self.eventid_pduid .get(event_id.as_bytes())? .map_or_else::, _, _>( - || Ok(self.eventid_outlierpdu.get(event_id.as_bytes())?), + || self.eventid_outlierpdu.get(event_id.as_bytes()), |pduid| { Ok(Some(self.pduid_pdu.get(&pduid)?.ok_or_else(|| { Error::bad_database("Invalid pduid in eventid_pduid.") @@ -493,8 +479,7 @@ impl Rooms { }, )? .map(|pdu| { - Ok(serde_json::from_slice(&pdu) - .map_err(|_| Error::bad_database("Invalid PDU in db."))?) + serde_json::from_slice(&pdu).map_err(|_| Error::bad_database("Invalid PDU in db.")) }) .transpose() } @@ -521,8 +506,7 @@ impl Rooms { }, )? .map(|pdu| { - Ok(serde_json::from_slice(&pdu) - .map_err(|_| Error::bad_database("Invalid PDU in db."))?) + serde_json::from_slice(&pdu).map_err(|_| Error::bad_database("Invalid PDU in db.")) }) .transpose() } @@ -534,7 +518,7 @@ impl Rooms { self.eventid_pduid .get(event_id.as_bytes())? .map_or_else::, _, _>( - || Ok(self.eventid_outlierpdu.get(event_id.as_bytes())?), + || self.eventid_outlierpdu.get(event_id.as_bytes()), |pduid| { Ok(Some(self.pduid_pdu.get(&pduid)?.ok_or_else(|| { Error::bad_database("Invalid pduid in eventid_pduid.") @@ -542,8 +526,7 @@ impl Rooms { }, )? .map(|pdu| { - Ok(serde_json::from_slice(&pdu) - .map_err(|_| Error::bad_database("Invalid PDU in db."))?) + serde_json::from_slice(&pdu).map_err(|_| Error::bad_database("Invalid PDU in db.")) }) .transpose() } @@ -594,12 +577,10 @@ impl Rooms { self.roomid_pduleaves .scan_prefix(prefix) .map(|(_, bytes)| { - Ok::<_, Error>( - EventId::try_from(utils::string_from_bytes(&bytes).map_err(|_| { - Error::bad_database("EventID in roomid_pduleaves is invalid unicode.") - })?) - .map_err(|_| Error::bad_database("EventId in roomid_pduleaves is invalid."))?, - ) + EventId::try_from(utils::string_from_bytes(&bytes).map_err(|_| { + Error::bad_database("EventID in roomid_pduleaves is invalid unicode.") + })?) + .map_err(|_| Error::bad_database("EventId in roomid_pduleaves is invalid.")) }) .collect() } @@ -1213,12 +1194,10 @@ impl Rooms { let create_event_content = create_event .as_ref() .map(|create_event| { - Ok::<_, Error>( - serde_json::from_value::>(create_event.content.clone()) - .expect("Raw::from_value always works.") - .deserialize() - .map_err(|_| Error::bad_database("Invalid PowerLevels event in db."))?, - ) + serde_json::from_value::>(create_event.content.clone()) + .expect("Raw::from_value always works.") + .deserialize() + .map_err(|_| Error::bad_database("Invalid PowerLevels event in db.")) }) .transpose()?; @@ -1382,13 +1361,12 @@ impl Rooms { .map_or_else(Vec::new, |users| { users .iter() - .map(|users| { + .filter_map(|users| { users .get("regex") .and_then(|regex| regex.as_str()) .and_then(|regex| Regex::new(regex).ok()) }) - .filter_map(|o| o) .collect::>() }); let aliases = namespaces @@ -1397,13 +1375,12 @@ impl Rooms { .map_or_else(Vec::new, |aliases| { aliases .iter() - .map(|aliases| { + .filter_map(|aliases| { aliases .get("regex") .and_then(|regex| regex.as_str()) .and_then(|regex| Regex::new(regex).ok()) }) - .filter_map(|o| o) .collect::>() }); let rooms = namespaces @@ -2011,10 +1988,10 @@ impl Rooms { prefix.push(0xff); self.aliasid_alias.scan_prefix(prefix).map(|(_, bytes)| { - Ok(utils::string_from_bytes(&bytes) + utils::string_from_bytes(&bytes) .map_err(|_| Error::bad_database("Invalid alias bytes in aliasid_alias."))? .try_into() - .map_err(|_| Error::bad_database("Invalid alias in aliasid_alias."))?) + .map_err(|_| Error::bad_database("Invalid alias in aliasid_alias.")) }) } @@ -2032,14 +2009,14 @@ impl Rooms { Ok(self.publicroomids.get(room_id.as_bytes())?.is_some()) } - pub fn public_rooms<'a>(&'a self) -> impl Iterator> + 'a { + pub fn public_rooms(&self) -> impl Iterator> + '_ { self.publicroomids.iter().map(|(bytes, _)| { - Ok( - RoomId::try_from(utils::string_from_bytes(&bytes).map_err(|_| { + RoomId::try_from( + utils::string_from_bytes(&bytes).map_err(|_| { Error::bad_database("Room ID in publicroomids is invalid unicode.") - })?) - .map_err(|_| Error::bad_database("Room ID in publicroomids is invalid."))?, + })?, ) + .map_err(|_| Error::bad_database("Room ID in publicroomids is invalid.")) }) } @@ -2105,34 +2082,27 @@ impl Rooms { &'a self, users: Vec, ) -> Result> + 'a> { - let iterators = users - .into_iter() - .map(move |user_id| { - let mut prefix = user_id.as_bytes().to_vec(); - prefix.push(0xff); + let iterators = users.into_iter().map(move |user_id| { + let mut prefix = user_id.as_bytes().to_vec(); + prefix.push(0xff); - Ok::<_, Error>( - self.userroomid_joined - .scan_prefix(prefix) - .map(|(key, _)| { - let roomid_index = key - .iter() - .enumerate() - .find(|(_, &b)| b == 0xff) - .ok_or_else(|| { - Error::bad_database("Invalid userroomid_joined in db.") - })? - .0 - + 1; // +1 because the room id starts AFTER the separator + self.userroomid_joined + .scan_prefix(prefix) + .map(|(key, _)| { + let roomid_index = key + .iter() + .enumerate() + .find(|(_, &b)| b == 0xff) + .ok_or_else(|| Error::bad_database("Invalid userroomid_joined in db."))? + .0 + + 1; // +1 because the room id starts AFTER the separator - let room_id = key[roomid_index..].to_vec(); + let room_id = key[roomid_index..].to_vec(); - Ok::<_, Error>(room_id) - }) - .filter_map(|r| r.ok()), - ) - }) - .filter_map(|r| r.ok()); + Ok::<_, Error>(room_id) + }) + .filter_map(|r| r.ok()) + }); // We use the default compare function because keys are sorted correctly (not reversed) Ok(utils::common_elements(iterators, Ord::cmp) @@ -2154,7 +2124,7 @@ impl Rooms { prefix.push(0xff); self.roomserverids.scan_prefix(prefix).map(|(key, _)| { - Ok(Box::::try_from( + Box::::try_from( utils::string_from_bytes( &key.rsplit(|&b| b == 0xff) .next() @@ -2164,7 +2134,7 @@ impl Rooms { Error::bad_database("Server name in roomserverids is invalid unicode.") })?, ) - .map_err(|_| Error::bad_database("Server name in roomserverids is invalid."))?) + .map_err(|_| Error::bad_database("Server name in roomserverids is invalid.")) }) } @@ -2177,7 +2147,7 @@ impl Rooms { prefix.push(0xff); self.serverroomids.scan_prefix(prefix).map(|(key, _)| { - Ok(RoomId::try_from( + RoomId::try_from( utils::string_from_bytes( &key.rsplit(|&b| b == 0xff) .next() @@ -2185,7 +2155,7 @@ impl Rooms { ) .map_err(|_| Error::bad_database("RoomId in serverroomids is invalid unicode."))?, ) - .map_err(|_| Error::bad_database("RoomId in serverroomids is invalid."))?) + .map_err(|_| Error::bad_database("RoomId in serverroomids is invalid.")) }) } @@ -2199,7 +2169,7 @@ impl Rooms { prefix.push(0xff); self.roomuserid_joined.scan_prefix(prefix).map(|(key, _)| { - Ok(UserId::try_from( + UserId::try_from( utils::string_from_bytes( &key.rsplit(|&b| b == 0xff) .next() @@ -2209,7 +2179,7 @@ impl Rooms { Error::bad_database("User ID in roomuserid_joined is invalid unicode.") })?, ) - .map_err(|_| Error::bad_database("User ID in roomuserid_joined is invalid."))?) + .map_err(|_| Error::bad_database("User ID in roomuserid_joined is invalid.")) }) } @@ -2224,7 +2194,7 @@ impl Rooms { self.roomuseroncejoinedids .scan_prefix(prefix) .map(|(key, _)| { - Ok(UserId::try_from( + UserId::try_from( utils::string_from_bytes( &key.rsplit(|&b| b == 0xff) .next() @@ -2234,7 +2204,7 @@ impl Rooms { Error::bad_database("User ID in room_useroncejoined is invalid unicode.") })?, ) - .map_err(|_| Error::bad_database("User ID in room_useroncejoined is invalid."))?) + .map_err(|_| Error::bad_database("User ID in room_useroncejoined is invalid.")) }) } @@ -2250,7 +2220,7 @@ impl Rooms { self.roomuserid_invitecount .scan_prefix(prefix) .map(|(key, _)| { - Ok(UserId::try_from( + UserId::try_from( utils::string_from_bytes( &key.rsplit(|&b| b == 0xff) .next() @@ -2260,7 +2230,7 @@ impl Rooms { Error::bad_database("User ID in roomuserid_invited is invalid unicode.") })?, ) - .map_err(|_| Error::bad_database("User ID in roomuserid_invited is invalid."))?) + .map_err(|_| Error::bad_database("User ID in roomuserid_invited is invalid.")) }) } @@ -2303,7 +2273,7 @@ impl Rooms { self.userroomid_joined .scan_prefix(user_id.as_bytes().to_vec()) .map(|(key, _)| { - Ok(RoomId::try_from( + RoomId::try_from( utils::string_from_bytes( &key.rsplit(|&b| b == 0xff) .next() @@ -2313,7 +2283,7 @@ impl Rooms { Error::bad_database("Room ID in userroomid_joined is invalid unicode.") })?, ) - .map_err(|_| Error::bad_database("Room ID in userroomid_joined is invalid."))?) + .map_err(|_| Error::bad_database("Room ID in userroomid_joined is invalid.")) }) } diff --git a/src/database/rooms/edus.rs b/src/database/rooms/edus.rs index 677d26eb..9a5cdeb2 100644 --- a/src/database/rooms/edus.rs +++ b/src/database/rooms/edus.rs @@ -306,12 +306,10 @@ impl RoomEdus { .typingid_userid .scan_prefix(prefix) .map(|(_, user_id)| { - Ok::<_, Error>( - UserId::try_from(utils::string_from_bytes(&user_id).map_err(|_| { - Error::bad_database("User ID in typingid_userid is invalid unicode.") - })?) - .map_err(|_| Error::bad_database("User ID in typingid_userid is invalid."))?, - ) + UserId::try_from(utils::string_from_bytes(&user_id).map_err(|_| { + Error::bad_database("User ID in typingid_userid is invalid unicode.") + })?) + .map_err(|_| Error::bad_database("User ID in typingid_userid is invalid.")) }) { user_ids.insert(user_id?); diff --git a/src/database/transaction_ids.rs b/src/database/transaction_ids.rs index 3e377798..f3467572 100644 --- a/src/database/transaction_ids.rs +++ b/src/database/transaction_ids.rs @@ -41,6 +41,6 @@ impl TransactionIds { key.extend_from_slice(txn_id.as_bytes()); // If there's no entry, this is a new transaction - Ok(self.userdevicetxnid_response.get(&key)?) + self.userdevicetxnid_response.get(&key) } } diff --git a/src/database/uiaa.rs b/src/database/uiaa.rs index f7f3d1f8..1372fef5 100644 --- a/src/database/uiaa.rs +++ b/src/database/uiaa.rs @@ -57,9 +57,7 @@ impl Uiaa { { let mut uiaainfo = session .as_ref() - .map(|session| { - Ok::<_, Error>(self.get_uiaa_session(&user_id, &device_id, session)?) - }) + .map(|session| self.get_uiaa_session(&user_id, &device_id, session)) .unwrap_or_else(|| Ok(uiaainfo.clone()))?; if uiaainfo.session.is_none() { diff --git a/src/database/users.rs b/src/database/users.rs index d89569a3..f99084fa 100644 --- a/src/database/users.rs +++ b/src/database/users.rs @@ -88,14 +88,12 @@ impl Users { } /// Returns an iterator over all users on this homeserver. - pub fn iter<'a>(&'a self) -> impl Iterator> + 'a { + pub fn iter(&self) -> impl Iterator> + '_ { self.userid_password.iter().map(|(bytes, _)| { - Ok( - UserId::try_from(utils::string_from_bytes(&bytes).map_err(|_| { - Error::bad_database("User ID in userid_password is invalid unicode.") - })?) - .map_err(|_| Error::bad_database("User ID in userid_password is invalid."))?, - ) + UserId::try_from(utils::string_from_bytes(&bytes).map_err(|_| { + Error::bad_database("User ID in userid_password is invalid unicode.") + })?) + .map_err(|_| Error::bad_database("User ID in userid_password is invalid.")) }) } @@ -588,16 +586,10 @@ impl Users { .iter_from(&start, false) .take_while(move |(k, _)| k.starts_with(&prefix)) .map(|(_, bytes)| { - Ok( - UserId::try_from(utils::string_from_bytes(&bytes).map_err(|_| { - Error::bad_database( - "User ID in devicekeychangeid_userid is invalid unicode.", - ) - })?) - .map_err(|_| { - Error::bad_database("User ID in devicekeychangeid_userid is invalid.") - })?, - ) + UserId::try_from(utils::string_from_bytes(&bytes).map_err(|_| { + Error::bad_database("User ID in devicekeychangeid_userid is invalid unicode.") + })?) + .map_err(|_| Error::bad_database("User ID in devicekeychangeid_userid is invalid.")) }) } @@ -863,9 +855,8 @@ impl Users { self.userdeviceid_metadata .scan_prefix(key) .map(|(_, bytes)| { - Ok(serde_json::from_slice::(&bytes).map_err(|_| { - Error::bad_database("Device in userdeviceid_metadata is invalid.") - })?) + serde_json::from_slice::(&bytes) + .map_err(|_| Error::bad_database("Device in userdeviceid_metadata is invalid.")) }) } diff --git a/src/server_server.rs b/src/server_server.rs index f6d65949..f34633ac 100644 --- a/src/server_server.rs +++ b/src/server_server.rs @@ -1691,13 +1691,12 @@ pub(crate) fn append_incoming_pdu( .map_or_else(Vec::new, |users| { users .iter() - .map(|users| { + .filter_map(|users| { users .get("regex") .and_then(|regex| regex.as_str()) .and_then(|regex| Regex::new(regex).ok()) }) - .filter_map(|o| o) .collect::>() }); let aliases = namespaces @@ -2026,12 +2025,10 @@ pub fn create_join_event_template_route( let create_event_content = create_event .as_ref() .map(|create_event| { - Ok::<_, Error>( - serde_json::from_value::>(create_event.content.clone()) - .expect("Raw::from_value always works.") - .deserialize() - .map_err(|_| Error::bad_database("Invalid PowerLevels event in db."))?, - ) + serde_json::from_value::>(create_event.content.clone()) + .expect("Raw::from_value always works.") + .deserialize() + .map_err(|_| Error::bad_database("Invalid PowerLevels event in db.")) }) .transpose()?; diff --git a/src/utils.rs b/src/utils.rs index 0c8fb5ca..2b5336c2 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -84,22 +84,19 @@ pub fn common_elements( let mut other_iterators = iterators.map(|i| i.peekable()).collect::>(); Some(first_iterator.filter(move |target| { - other_iterators - .iter_mut() - .map(|it| { - while let Some(element) = it.peek() { - match check_order(element, target) { - Ordering::Greater => return false, // We went too far - Ordering::Equal => return true, // Element is in both iters - Ordering::Less => { - // Keep searching - it.next(); - } + other_iterators.iter_mut().all(|it| { + while let Some(element) = it.peek() { + match check_order(element, target) { + Ordering::Greater => return false, // We went too far + Ordering::Equal => return true, // Element is in both iters + Ordering::Less => { + // Keep searching + it.next(); } } - false - }) - .all(|b| b) + } + false + }) })) }