refactor(core): remove EitherIter

`EitherIter` is an implementation detail and can be removed without breaking users.

Related: https://github.com/libp2p/rust-libp2p/pull/3746.

Pull-Request: #3841.
This commit is contained in:
Thomas Eizinger
2023-04-27 15:04:16 +02:00
committed by GitHub
parent fadcc43e69
commit d66c8271b5

View File

@ -24,6 +24,7 @@ use crate::{
}; };
use either::Either; use either::Either;
use futures::future; use futures::future;
use std::iter::Map;
impl<A, B> UpgradeInfo for Either<A, B> impl<A, B> UpgradeInfo for Either<A, B>
where where
@ -31,15 +32,15 @@ where
B: UpgradeInfo, B: UpgradeInfo,
{ {
type Info = EitherName<A::Info, B::Info>; type Info = EitherName<A::Info, B::Info>;
type InfoIter = EitherIter< type InfoIter = Either<
<A::InfoIter as IntoIterator>::IntoIter, Map<<A::InfoIter as IntoIterator>::IntoIter, fn(A::Info) -> Self::Info>,
<B::InfoIter as IntoIterator>::IntoIter, Map<<B::InfoIter as IntoIterator>::IntoIter, fn(B::Info) -> Self::Info>,
>; >;
fn protocol_info(&self) -> Self::InfoIter { fn protocol_info(&self) -> Self::InfoIter {
match self { match self {
Either::Left(a) => EitherIter::A(a.protocol_info().into_iter()), Either::Left(a) => Either::Left(a.protocol_info().into_iter().map(EitherName::A)),
Either::Right(b) => EitherIter::B(b.protocol_info().into_iter()), Either::Right(b) => Either::Right(b.protocol_info().into_iter().map(EitherName::B)),
} }
} }
} }
@ -87,32 +88,3 @@ where
} }
} }
} }
/// A type to represent two possible `Iterator` types.
#[derive(Debug, Clone)]
pub enum EitherIter<A, B> {
A(A),
B(B),
}
impl<A, B> Iterator for EitherIter<A, B>
where
A: Iterator,
B: Iterator,
{
type Item = EitherName<A::Item, B::Item>;
fn next(&mut self) -> Option<Self::Item> {
match self {
EitherIter::A(a) => a.next().map(EitherName::A),
EitherIter::B(b) => b.next().map(EitherName::B),
}
}
fn size_hint(&self) -> (usize, Option<usize>) {
match self {
EitherIter::A(a) => a.size_hint(),
EitherIter::B(b) => b.size_hint(),
}
}
}