diff --git a/Cargo.toml b/Cargo.toml
index 5103c7802b8..c0f97e48109 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -132,6 +132,7 @@ libp2p-gossipsub = { version = "0.44.0", path = "protocols/gossipsub", optional
[dev-dependencies]
async-std = { version = "1.6.2", features = ["attributes"] }
async-trait = "0.1"
+either = "1.8.0"
env_logger = "0.10.0"
clap = { version = "4.0.13", features = ["derive"] }
tokio = { version = "1.15", features = ["io-util", "io-std", "macros", "rt", "rt-multi-thread"] }
diff --git a/core/CHANGELOG.md b/core/CHANGELOG.md
index a7e24f5d616..f9f293e6e38 100644
--- a/core/CHANGELOG.md
+++ b/core/CHANGELOG.md
@@ -12,11 +12,14 @@
- Improve error messages in case keys cannot be decoded because of missing feature flags. See [PR 2972].
+- Remove `EitherError` in favor of `either::Either`. See [PR 3337].
+
[PR 3031]: https://github.com/libp2p/rust-libp2p/pull/3031
[PR 3058]: https://github.com/libp2p/rust-libp2p/pull/3058
[PR 3097]: https://github.com/libp2p/rust-libp2p/pull/3097
[PR 3090]: https://github.com/libp2p/rust-libp2p/pull/3090
[PR 2972]: https://github.com/libp2p/rust-libp2p/pull/2972
+[PR 3337]: https://github.com/libp2p/rust-libp2p/pull/3337
# 0.37.0
diff --git a/core/src/either.rs b/core/src/either.rs
index a34552bf28f..411251cbd84 100644
--- a/core/src/either.rs
+++ b/core/src/either.rs
@@ -24,44 +24,13 @@ use crate::{
transport::{ListenerId, Transport, TransportError, TransportEvent},
Multiaddr, ProtocolName,
};
+use either::Either;
use futures::{
io::{IoSlice, IoSliceMut},
prelude::*,
};
use pin_project::pin_project;
-use std::{fmt, io, pin::Pin, task::Context, task::Poll};
-
-#[derive(Debug, Copy, Clone)]
-pub enum EitherError {
- A(A),
- B(B),
-}
-
-impl fmt::Display for EitherError
-where
- A: fmt::Display,
- B: fmt::Display,
-{
- fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
- match self {
- EitherError::A(a) => a.fmt(f),
- EitherError::B(b) => b.fmt(f),
- }
- }
-}
-
-impl std::error::Error for EitherError
-where
- A: std::error::Error,
- B: std::error::Error,
-{
- fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
- match self {
- EitherError::A(a) => a.source(),
- EitherError::B(b) => b.source(),
- }
- }
-}
+use std::{io, pin::Pin, task::Context, task::Poll};
/// Implements `AsyncRead` and `AsyncWrite` and dispatches all method calls to
/// either `First` or `Second`.
@@ -147,15 +116,15 @@ where
A: TryStream,
B: TryStream,
{
- type Item = Result>;
+ type Item = Result>;
fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll