From ade1ea4216136e05b02585e1168ea154fd08988f Mon Sep 17 00:00:00 2001 From: Bjerg Date: Thu, 5 Jan 2023 23:38:31 +0100 Subject: [PATCH] refactor: clean up `StateFetcher::next_peer` (#738) * refactor: clean up `StateFetcher::next_peer` The `&mut Peer` is unused, so we do not need to return it. * chore: idiomatic rust --- crates/net/network/src/fetch/mod.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/crates/net/network/src/fetch/mod.rs b/crates/net/network/src/fetch/mod.rs index 871b4f223c..0256cfdb17 100644 --- a/crates/net/network/src/fetch/mod.rs +++ b/crates/net/network/src/fetch/mod.rs @@ -103,8 +103,8 @@ impl StateFetcher { } /// Returns the _next_ idle peer that's ready to accept a request. - fn next_peer(&mut self) -> Option<(&PeerId, &mut Peer)> { - self.peers.iter_mut().find(|(_, peer)| peer.state.is_idle()) + fn next_peer(&self) -> Option<&PeerId> { + self.peers.iter().find_map(|(peer_id, peer)| peer.state.is_idle().then_some(peer_id)) } /// Returns the next action to return @@ -114,8 +114,8 @@ impl StateFetcher { return PollAction::NoRequests } - let peer_id = if let Some(peer) = self.next_peer() { - *peer.0 + let peer_id = if let Some(peer_id) = self.next_peer() { + *peer_id } else { return PollAction::NoPeersAvailable };