From eafb88c345a2e88407d89448c2c2da93e4435bbf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20Frosteg=C3=A5rd?= Date: Sat, 23 Oct 2021 15:12:12 +0200 Subject: [PATCH] aquatic_udp: use const for empty scrape statistics --- aquatic_udp/src/lib/common/handlers.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/aquatic_udp/src/lib/common/handlers.rs b/aquatic_udp/src/lib/common/handlers.rs index daf4ba9..773d268 100644 --- a/aquatic_udp/src/lib/common/handlers.rs +++ b/aquatic_udp/src/lib/common/handlers.rs @@ -141,7 +141,7 @@ pub fn handle_scrape_request( src: SocketAddr, request: ScrapeRequest, ) -> ScrapeResponse { - let empty_stats = create_torrent_scrape_statistics(0, 0); + const EMPTY_STATS: TorrentScrapeStatistics = create_torrent_scrape_statistics(0, 0); let mut stats: Vec = Vec::with_capacity(request.info_hashes.len()); @@ -155,7 +155,7 @@ pub fn handle_scrape_request( torrent_data.num_leechers as i32, )); } else { - stats.push(empty_stats); + stats.push(EMPTY_STATS); } } } else { @@ -166,7 +166,7 @@ pub fn handle_scrape_request( torrent_data.num_leechers as i32, )); } else { - stats.push(empty_stats); + stats.push(EMPTY_STATS); } } } @@ -178,7 +178,7 @@ pub fn handle_scrape_request( } #[inline(always)] -fn create_torrent_scrape_statistics(seeders: i32, leechers: i32) -> TorrentScrapeStatistics { +const fn create_torrent_scrape_statistics(seeders: i32, leechers: i32) -> TorrentScrapeStatistics { TorrentScrapeStatistics { seeders: NumberOfPeers(seeders), completed: NumberOfDownloads(0), // No implementation planned