refactor(core)!: remove EitherError in favor of either::Either (#3337)

Defining our own `EitherError` type has no value now that `Either` provides the same implementation.

Related: https://github.com/libp2p/rust-libp2p/issues/3271
This commit is contained in:
Thomas Eizinger
2023-01-18 10:05:59 +11:00
committed by GitHub
parent 29a77164f1
commit f4fed3880b
17 changed files with 118 additions and 144 deletions

View File

@ -25,7 +25,7 @@ use crate::handler::{
};
use crate::upgrade::SendWrapper;
use either::Either;
use libp2p_core::either::{EitherError, EitherOutput};
use libp2p_core::either::EitherOutput;
use libp2p_core::upgrade::{EitherUpgrade, UpgradeError};
use libp2p_core::{ConnectedPoint, PeerId};
use std::task::{Context, Poll};
@ -145,14 +145,14 @@ where
fn transpose(self) -> Either<DialUpgradeError<LOOI, LOP>, DialUpgradeError<ROOI, ROP>> {
match self {
DialUpgradeError {
error: ConnectionHandlerUpgrErr::Upgrade(UpgradeError::Apply(EitherError::A(error))),
error: ConnectionHandlerUpgrErr::Upgrade(UpgradeError::Apply(Either::Left(error))),
info: Either::Left(info),
} => Either::Left(DialUpgradeError {
error: ConnectionHandlerUpgrErr::Upgrade(UpgradeError::Apply(error)),
info,
}),
DialUpgradeError {
error: ConnectionHandlerUpgrErr::Upgrade(UpgradeError::Apply(EitherError::B(error))),
error: ConnectionHandlerUpgrErr::Upgrade(UpgradeError::Apply(Either::Right(error))),
info: Either::Right(info),
} => Either::Right(DialUpgradeError {
error: ConnectionHandlerUpgrErr::Upgrade(UpgradeError::Apply(error)),
@ -214,14 +214,14 @@ where
fn transpose(self) -> Either<ListenUpgradeError<LIOI, LIP>, ListenUpgradeError<RIOI, RIP>> {
match self {
ListenUpgradeError {
error: ConnectionHandlerUpgrErr::Upgrade(UpgradeError::Apply(EitherError::A(error))),
error: ConnectionHandlerUpgrErr::Upgrade(UpgradeError::Apply(Either::Left(error))),
info: Either::Left(info),
} => Either::Left(ListenUpgradeError {
error: ConnectionHandlerUpgrErr::Upgrade(UpgradeError::Apply(error)),
info,
}),
ListenUpgradeError {
error: ConnectionHandlerUpgrErr::Upgrade(UpgradeError::Apply(EitherError::B(error))),
error: ConnectionHandlerUpgrErr::Upgrade(UpgradeError::Apply(Either::Right(error))),
info: Either::Right(info),
} => Either::Right(ListenUpgradeError {
error: ConnectionHandlerUpgrErr::Upgrade(UpgradeError::Apply(error)),

View File

@ -28,7 +28,7 @@ use crate::upgrade::SendWrapper;
use either::Either;
use libp2p_core::{
either::{EitherError, EitherOutput},
either::EitherOutput,
upgrade::{EitherUpgrade, NegotiationError, ProtocolError, SelectUpgrade, UpgradeError},
ConnectedPoint, PeerId,
};
@ -186,7 +186,7 @@ where
}),
DialUpgradeError {
info: EitherOutput::First(info),
error: ConnectionHandlerUpgrErr::Upgrade(UpgradeError::Apply(EitherError::A(err))),
error: ConnectionHandlerUpgrErr::Upgrade(UpgradeError::Apply(Either::Left(err))),
} => Either::Left(DialUpgradeError {
info,
error: ConnectionHandlerUpgrErr::Upgrade(UpgradeError::Apply(err)),
@ -214,7 +214,7 @@ where
}),
DialUpgradeError {
info: EitherOutput::Second(info),
error: ConnectionHandlerUpgrErr::Upgrade(UpgradeError::Apply(EitherError::B(err))),
error: ConnectionHandlerUpgrErr::Upgrade(UpgradeError::Apply(Either::Right(err))),
} => Either::Right(DialUpgradeError {
info,
error: ConnectionHandlerUpgrErr::Upgrade(UpgradeError::Apply(err)),
@ -318,14 +318,14 @@ where
error: ConnectionHandlerUpgrErr::Upgrade(UpgradeError::Select(e2)),
}));
}
ConnectionHandlerUpgrErr::Upgrade(UpgradeError::Apply(EitherError::A(e))) => {
ConnectionHandlerUpgrErr::Upgrade(UpgradeError::Apply(Either::Left(e))) => {
self.proto1
.on_connection_event(ConnectionEvent::ListenUpgradeError(ListenUpgradeError {
info: i1,
error: ConnectionHandlerUpgrErr::Upgrade(UpgradeError::Apply(e)),
}));
}
ConnectionHandlerUpgrErr::Upgrade(UpgradeError::Apply(EitherError::B(e))) => {
ConnectionHandlerUpgrErr::Upgrade(UpgradeError::Apply(Either::Right(e))) => {
self.proto2
.on_connection_event(ConnectionEvent::ListenUpgradeError(ListenUpgradeError {
info: i2,
@ -343,7 +343,7 @@ where
{
type InEvent = EitherOutput<TProto1::InEvent, TProto2::InEvent>;
type OutEvent = EitherOutput<TProto1::OutEvent, TProto2::OutEvent>;
type Error = EitherError<TProto1::Error, TProto2::Error>;
type Error = Either<TProto1::Error, TProto2::Error>;
type InboundProtocol = SelectUpgrade<
SendWrapper<<TProto1 as ConnectionHandler>::InboundProtocol>,
SendWrapper<<TProto2 as ConnectionHandler>::InboundProtocol>,
@ -395,7 +395,7 @@ where
return Poll::Ready(ConnectionHandlerEvent::Custom(EitherOutput::First(event)));
}
Poll::Ready(ConnectionHandlerEvent::Close(event)) => {
return Poll::Ready(ConnectionHandlerEvent::Close(EitherError::A(event)));
return Poll::Ready(ConnectionHandlerEvent::Close(Either::Left(event)));
}
Poll::Ready(ConnectionHandlerEvent::OutboundSubstreamRequest { protocol }) => {
return Poll::Ready(ConnectionHandlerEvent::OutboundSubstreamRequest {
@ -412,7 +412,7 @@ where
return Poll::Ready(ConnectionHandlerEvent::Custom(EitherOutput::Second(event)));
}
Poll::Ready(ConnectionHandlerEvent::Close(event)) => {
return Poll::Ready(ConnectionHandlerEvent::Close(EitherError::B(event)));
return Poll::Ready(ConnectionHandlerEvent::Close(Either::Right(event)));
}
Poll::Ready(ConnectionHandlerEvent::OutboundSubstreamRequest { protocol }) => {
return Poll::Ready(ConnectionHandlerEvent::OutboundSubstreamRequest {