diff --git a/core/src/upgrade/either.rs b/core/src/upgrade/either.rs index 563e7651c07..0bda47ca9d0 100644 --- a/core/src/upgrade/either.rs +++ b/core/src/upgrade/either.rs @@ -24,6 +24,7 @@ use crate::{ }; use either::Either; use futures::future; +use std::iter::Map; impl UpgradeInfo for Either where @@ -31,15 +32,15 @@ where B: UpgradeInfo, { type Info = EitherName; - type InfoIter = EitherIter< - ::IntoIter, - ::IntoIter, + type InfoIter = Either< + Map<::IntoIter, fn(A::Info) -> Self::Info>, + Map<::IntoIter, fn(B::Info) -> Self::Info>, >; fn protocol_info(&self) -> Self::InfoIter { match self { - Either::Left(a) => EitherIter::A(a.protocol_info().into_iter()), - Either::Right(b) => EitherIter::B(b.protocol_info().into_iter()), + Either::Left(a) => Either::Left(a.protocol_info().into_iter().map(EitherName::A)), + 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(A), - B(B), -} - -impl Iterator for EitherIter -where - A: Iterator, - B: Iterator, -{ - type Item = EitherName; - - fn next(&mut self) -> Option { - match self { - EitherIter::A(a) => a.next().map(EitherName::A), - EitherIter::B(b) => b.next().map(EitherName::B), - } - } - - fn size_hint(&self) -> (usize, Option) { - match self { - EitherIter::A(a) => a.size_hint(), - EitherIter::B(b) => b.size_hint(), - } - } -}