Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 6 additions & 34 deletions core/src/upgrade/either.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,23 @@ use crate::{
};
use either::Either;
use futures::future;
use std::iter::Map;

impl<A, B> UpgradeInfo for Either<A, B>
where
A: UpgradeInfo,
B: UpgradeInfo,
{
type Info = EitherName<A::Info, B::Info>;
type InfoIter = EitherIter<
<A::InfoIter as IntoIterator>::IntoIter,
<B::InfoIter as IntoIterator>::IntoIter,
type InfoIter = Either<
Map<<A::InfoIter as IntoIterator>::IntoIter, fn(A::Info) -> Self::Info>,
Map<<B::InfoIter as IntoIterator>::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)),
}
}
}
Expand Down Expand Up @@ -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(),
}
}
}