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
This commit is contained in:
Bjerg
2023-01-05 23:38:31 +01:00
committed by GitHub
parent ee8b0efed6
commit ade1ea4216

View File

@ -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
};