From 80171170c856d7d8623828cd900c50e20f4367f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20Frosteg=C3=A5rd?= Date: Sat, 16 Apr 2022 02:28:03 +0200 Subject: [PATCH] udp: request workers: improve handle_scrape_request code --- aquatic_udp/src/workers/request/mod.rs | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/aquatic_udp/src/workers/request/mod.rs b/aquatic_udp/src/workers/request/mod.rs index 39b1517..78cd2e3 100644 --- a/aquatic_udp/src/workers/request/mod.rs +++ b/aquatic_udp/src/workers/request/mod.rs @@ -193,16 +193,18 @@ fn handle_scrape_request( .info_hashes .into_iter() .map(|(i, info_hash)| { - let s = if let Some(torrent_data) = torrents.0.get(&info_hash) { - create_torrent_scrape_statistics( - torrent_data.num_seeders as i32, - torrent_data.num_leechers as i32, - ) - } else { - EMPTY_STATS - }; + let stats = torrents + .0 + .get(&info_hash) + .map(|torrent_data| { + create_torrent_scrape_statistics( + torrent_data.num_seeders as i32, + torrent_data.num_leechers as i32, + ) + }) + .unwrap_or(EMPTY_STATS); - (i, s) + (i, stats) }) .collect();