mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-06-23 06:41:34 +00:00
refactor(core)!: remove EitherUpgrade
(#3339)
We don't need to define our own type here, we can simply implement `UpgradeInfo`, `InboundUpgrade` and `OutboundUpgrade` on `either::Either`.
This commit is contained in:
@ -74,7 +74,6 @@ use futures::future::Future;
|
||||
pub use self::{
|
||||
apply::{apply, apply_inbound, apply_outbound, InboundUpgradeApply, OutboundUpgradeApply},
|
||||
denied::DeniedUpgrade,
|
||||
either::EitherUpgrade,
|
||||
error::UpgradeError,
|
||||
from_fn::{from_fn, FromFnUpgrade},
|
||||
map::{MapInboundUpgrade, MapInboundUpgradeErr, MapOutboundUpgrade, MapOutboundUpgradeErr},
|
||||
|
@ -24,14 +24,7 @@ use crate::{
|
||||
};
|
||||
use either::Either;
|
||||
|
||||
/// A type to represent two possible upgrade types (inbound or outbound).
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum EitherUpgrade<A, B> {
|
||||
A(A),
|
||||
B(B),
|
||||
}
|
||||
|
||||
impl<A, B> UpgradeInfo for EitherUpgrade<A, B>
|
||||
impl<A, B> UpgradeInfo for Either<A, B>
|
||||
where
|
||||
A: UpgradeInfo,
|
||||
B: UpgradeInfo,
|
||||
@ -44,13 +37,13 @@ where
|
||||
|
||||
fn protocol_info(&self) -> Self::InfoIter {
|
||||
match self {
|
||||
EitherUpgrade::A(a) => EitherIter::A(a.protocol_info().into_iter()),
|
||||
EitherUpgrade::B(b) => EitherIter::B(b.protocol_info().into_iter()),
|
||||
Either::Left(a) => EitherIter::A(a.protocol_info().into_iter()),
|
||||
Either::Right(b) => EitherIter::B(b.protocol_info().into_iter()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<C, A, B, TA, TB, EA, EB> InboundUpgrade<C> for EitherUpgrade<A, B>
|
||||
impl<C, A, B, TA, TB, EA, EB> InboundUpgrade<C> for Either<A, B>
|
||||
where
|
||||
A: InboundUpgrade<C, Output = TA, Error = EA>,
|
||||
B: InboundUpgrade<C, Output = TB, Error = EB>,
|
||||
@ -61,10 +54,10 @@ where
|
||||
|
||||
fn upgrade_inbound(self, sock: C, info: Self::Info) -> Self::Future {
|
||||
match (self, info) {
|
||||
(EitherUpgrade::A(a), EitherName::A(info)) => {
|
||||
(Either::Left(a), EitherName::A(info)) => {
|
||||
EitherFuture2::A(a.upgrade_inbound(sock, info))
|
||||
}
|
||||
(EitherUpgrade::B(b), EitherName::B(info)) => {
|
||||
(Either::Right(b), EitherName::B(info)) => {
|
||||
EitherFuture2::B(b.upgrade_inbound(sock, info))
|
||||
}
|
||||
_ => panic!("Invalid invocation of EitherUpgrade::upgrade_inbound"),
|
||||
@ -72,7 +65,7 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
impl<C, A, B, TA, TB, EA, EB> OutboundUpgrade<C> for EitherUpgrade<A, B>
|
||||
impl<C, A, B, TA, TB, EA, EB> OutboundUpgrade<C> for Either<A, B>
|
||||
where
|
||||
A: OutboundUpgrade<C, Output = TA, Error = EA>,
|
||||
B: OutboundUpgrade<C, Output = TB, Error = EB>,
|
||||
@ -83,10 +76,10 @@ where
|
||||
|
||||
fn upgrade_outbound(self, sock: C, info: Self::Info) -> Self::Future {
|
||||
match (self, info) {
|
||||
(EitherUpgrade::A(a), EitherName::A(info)) => {
|
||||
(Either::Left(a), EitherName::A(info)) => {
|
||||
EitherFuture2::A(a.upgrade_outbound(sock, info))
|
||||
}
|
||||
(EitherUpgrade::B(b), EitherName::B(info)) => {
|
||||
(Either::Right(b), EitherName::B(info)) => {
|
||||
EitherFuture2::B(b.upgrade_outbound(sock, info))
|
||||
}
|
||||
_ => panic!("Invalid invocation of EitherUpgrade::upgrade_outbound"),
|
||||
|
Reference in New Issue
Block a user