Skip to content

Commit 73cbbe2

Browse files
refactor(core)!: remove EitherFuture2 (#3340)
We can completely replace `EitherFuture2` with `EitherFuture`. `EitherFuture` itself cannot be removed for now because the `Future` implementation on `future::Either` forces both `Future`s to evaluate to the same type.
1 parent 475dc80 commit 73cbbe2

File tree

4 files changed

+18
-41
lines changed

4 files changed

+18
-41
lines changed

core/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525

2626
- Remove `EitherUpgrade` in favor of implementing `UpgradeInfo`, `InboundUpgrade` and `OutboundUpgrade` on `either::Either`. See [PR 3339].
2727

28+
- Remove `EitherFuture2` in favor of `EitherFuture`. See [PR 3340].
29+
2830
[PR 3031]: https://github.com/libp2p/rust-libp2p/pull/3031
2931
[PR 3058]: https://github.com/libp2p/rust-libp2p/pull/3058
3032
[PR 3097]: https://github.com/libp2p/rust-libp2p/pull/3097
@@ -33,6 +35,7 @@
3335
[PR 3337]: https://github.com/libp2p/rust-libp2p/pull/3337
3436
[PR 3338]: https://github.com/libp2p/rust-libp2p/pull/3338
3537
[PR 3339]: https://github.com/libp2p/rust-libp2p/pull/3339
38+
[PR 3340]: https://github.com/libp2p/rust-libp2p/pull/3340
3639

3740
# 0.37.0
3841

core/src/either.rs

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -252,33 +252,6 @@ where
252252
}
253253
}
254254

255-
#[pin_project(project = EitherFuture2Proj)]
256-
#[derive(Debug, Copy, Clone)]
257-
#[must_use = "futures do nothing unless polled"]
258-
pub enum EitherFuture2<A, B> {
259-
A(#[pin] A),
260-
B(#[pin] B),
261-
}
262-
263-
impl<AFut, BFut, AItem, BItem, AError, BError> Future for EitherFuture2<AFut, BFut>
264-
where
265-
AFut: TryFuture<Ok = AItem, Error = AError>,
266-
BFut: TryFuture<Ok = BItem, Error = BError>,
267-
{
268-
type Output = Result<EitherOutput<AItem, BItem>, Either<AError, BError>>;
269-
270-
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
271-
match self.project() {
272-
EitherFuture2Proj::A(a) => TryFuture::try_poll(a, cx)
273-
.map_ok(EitherOutput::First)
274-
.map_err(Either::Left),
275-
EitherFuture2Proj::B(a) => TryFuture::try_poll(a, cx)
276-
.map_ok(EitherOutput::Second)
277-
.map_err(Either::Right),
278-
}
279-
}
280-
}
281-
282255
#[derive(Debug, Clone)]
283256
pub enum EitherName<A, B> {
284257
A(A),

core/src/upgrade/either.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
// DEALINGS IN THE SOFTWARE.
2020

2121
use crate::{
22-
either::{EitherFuture2, EitherName, EitherOutput},
22+
either::{EitherFuture, EitherName, EitherOutput},
2323
upgrade::{InboundUpgrade, OutboundUpgrade, UpgradeInfo},
2424
};
2525
use either::Either;
@@ -50,15 +50,15 @@ where
5050
{
5151
type Output = EitherOutput<TA, TB>;
5252
type Error = Either<EA, EB>;
53-
type Future = EitherFuture2<A::Future, B::Future>;
53+
type Future = EitherFuture<A::Future, B::Future>;
5454

5555
fn upgrade_inbound(self, sock: C, info: Self::Info) -> Self::Future {
5656
match (self, info) {
5757
(Either::Left(a), EitherName::A(info)) => {
58-
EitherFuture2::A(a.upgrade_inbound(sock, info))
58+
EitherFuture::First(a.upgrade_inbound(sock, info))
5959
}
6060
(Either::Right(b), EitherName::B(info)) => {
61-
EitherFuture2::B(b.upgrade_inbound(sock, info))
61+
EitherFuture::Second(b.upgrade_inbound(sock, info))
6262
}
6363
_ => panic!("Invalid invocation of EitherUpgrade::upgrade_inbound"),
6464
}
@@ -72,15 +72,15 @@ where
7272
{
7373
type Output = EitherOutput<TA, TB>;
7474
type Error = Either<EA, EB>;
75-
type Future = EitherFuture2<A::Future, B::Future>;
75+
type Future = EitherFuture<A::Future, B::Future>;
7676

7777
fn upgrade_outbound(self, sock: C, info: Self::Info) -> Self::Future {
7878
match (self, info) {
7979
(Either::Left(a), EitherName::A(info)) => {
80-
EitherFuture2::A(a.upgrade_outbound(sock, info))
80+
EitherFuture::First(a.upgrade_outbound(sock, info))
8181
}
8282
(Either::Right(b), EitherName::B(info)) => {
83-
EitherFuture2::B(b.upgrade_outbound(sock, info))
83+
EitherFuture::Second(b.upgrade_outbound(sock, info))
8484
}
8585
_ => panic!("Invalid invocation of EitherUpgrade::upgrade_outbound"),
8686
}

core/src/upgrade/select.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@
1818
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
1919
// DEALINGS IN THE SOFTWARE.
2020

21+
use crate::either::EitherFuture;
2122
use crate::{
22-
either::{EitherFuture2, EitherName, EitherOutput},
23+
either::{EitherName, EitherOutput},
2324
upgrade::{InboundUpgrade, OutboundUpgrade, UpgradeInfo},
2425
};
2526
use either::Either;
@@ -66,12 +67,12 @@ where
6667
{
6768
type Output = EitherOutput<TA, TB>;
6869
type Error = Either<EA, EB>;
69-
type Future = EitherFuture2<A::Future, B::Future>;
70+
type Future = EitherFuture<A::Future, B::Future>;
7071

7172
fn upgrade_inbound(self, sock: C, info: Self::Info) -> Self::Future {
7273
match info {
73-
EitherName::A(info) => EitherFuture2::A(self.0.upgrade_inbound(sock, info)),
74-
EitherName::B(info) => EitherFuture2::B(self.1.upgrade_inbound(sock, info)),
74+
EitherName::A(info) => EitherFuture::First(self.0.upgrade_inbound(sock, info)),
75+
EitherName::B(info) => EitherFuture::Second(self.1.upgrade_inbound(sock, info)),
7576
}
7677
}
7778
}
@@ -83,12 +84,12 @@ where
8384
{
8485
type Output = EitherOutput<TA, TB>;
8586
type Error = Either<EA, EB>;
86-
type Future = EitherFuture2<A::Future, B::Future>;
87+
type Future = EitherFuture<A::Future, B::Future>;
8788

8889
fn upgrade_outbound(self, sock: C, info: Self::Info) -> Self::Future {
8990
match info {
90-
EitherName::A(info) => EitherFuture2::A(self.0.upgrade_outbound(sock, info)),
91-
EitherName::B(info) => EitherFuture2::B(self.1.upgrade_outbound(sock, info)),
91+
EitherName::A(info) => EitherFuture::First(self.0.upgrade_outbound(sock, info)),
92+
EitherName::B(info) => EitherFuture::Second(self.1.upgrade_outbound(sock, info)),
9293
}
9394
}
9495
}

0 commit comments

Comments
 (0)