kad: Avoid from/into IteratorIndex. (#1623)

This caused problems with type inference.
This commit is contained in:
Toralf Wittner
2020-06-23 11:28:43 +02:00
committed by GitHub
parent 0eef487ef8
commit 32cb0a56bd

View File

@ -24,7 +24,7 @@ use libp2p_core::PeerId;
use std::{ use std::{
collections::HashMap, collections::HashMap,
iter::{Cycle, Map, Peekable}, iter::{Cycle, Map, Peekable},
ops::{Add, Index, IndexMut, Range}, ops::{Index, IndexMut, Range},
}; };
use wasm_timer::Instant; use wasm_timer::Instant;
@ -114,7 +114,7 @@ impl ClosestDisjointPeersIter {
} }
for (i, iter) in &mut self.iters.iter_mut().enumerate() { for (i, iter) in &mut self.iters.iter_mut().enumerate() {
if i != (*initiated_by).into() { if IteratorIndex(i) != *initiated_by {
// This iterator never triggered an actual request to the // This iterator never triggered an actual request to the
// given peer - thus ignore the returned boolean. // given peer - thus ignore the returned boolean.
iter.on_failure(peer); iter.on_failure(peer);
@ -162,7 +162,7 @@ impl ClosestDisjointPeersIter {
} }
for (i, iter) in &mut self.iters.iter_mut().enumerate() { for (i, iter) in &mut self.iters.iter_mut().enumerate() {
if i != (*initiated_by).into() { if IteratorIndex(i) != *initiated_by {
// Only report the success to all remaining not-first // Only report the success to all remaining not-first
// iterators. Do not pass the `closer_peers` in order to // iterators. Do not pass the `closer_peers` in order to
// uphold the S/Kademlia disjoint paths guarantee. // uphold the S/Kademlia disjoint paths guarantee.
@ -323,26 +323,6 @@ impl ClosestDisjointPeersIter {
#[derive(Debug, Clone, Copy, PartialEq, Eq)] #[derive(Debug, Clone, Copy, PartialEq, Eq)]
struct IteratorIndex(usize); struct IteratorIndex(usize);
impl From<usize> for IteratorIndex {
fn from(i: usize) -> Self {
IteratorIndex(i)
}
}
impl From<IteratorIndex> for usize {
fn from(i: IteratorIndex) -> Self {
i.0
}
}
impl Add<usize> for IteratorIndex {
type Output = Self;
fn add(self, rhs: usize) -> Self::Output {
(self.0 + rhs).into()
}
}
impl Index<IteratorIndex> for Vec<ClosestPeersIter> { impl Index<IteratorIndex> for Vec<ClosestPeersIter> {
type Output = ClosestPeersIter; type Output = ClosestPeersIter;