mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-05-29 10:41:21 +00:00
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.
This commit is contained in:
parent
475dc80a07
commit
73cbbe2967
@ -25,6 +25,8 @@
|
|||||||
|
|
||||||
- Remove `EitherUpgrade` in favor of implementing `UpgradeInfo`, `InboundUpgrade` and `OutboundUpgrade` on `either::Either`. See [PR 3339].
|
- Remove `EitherUpgrade` in favor of implementing `UpgradeInfo`, `InboundUpgrade` and `OutboundUpgrade` on `either::Either`. See [PR 3339].
|
||||||
|
|
||||||
|
- Remove `EitherFuture2` in favor of `EitherFuture`. See [PR 3340].
|
||||||
|
|
||||||
[PR 3031]: https://github.com/libp2p/rust-libp2p/pull/3031
|
[PR 3031]: https://github.com/libp2p/rust-libp2p/pull/3031
|
||||||
[PR 3058]: https://github.com/libp2p/rust-libp2p/pull/3058
|
[PR 3058]: https://github.com/libp2p/rust-libp2p/pull/3058
|
||||||
[PR 3097]: https://github.com/libp2p/rust-libp2p/pull/3097
|
[PR 3097]: https://github.com/libp2p/rust-libp2p/pull/3097
|
||||||
@ -33,6 +35,7 @@
|
|||||||
[PR 3337]: https://github.com/libp2p/rust-libp2p/pull/3337
|
[PR 3337]: https://github.com/libp2p/rust-libp2p/pull/3337
|
||||||
[PR 3338]: https://github.com/libp2p/rust-libp2p/pull/3338
|
[PR 3338]: https://github.com/libp2p/rust-libp2p/pull/3338
|
||||||
[PR 3339]: https://github.com/libp2p/rust-libp2p/pull/3339
|
[PR 3339]: https://github.com/libp2p/rust-libp2p/pull/3339
|
||||||
|
[PR 3340]: https://github.com/libp2p/rust-libp2p/pull/3340
|
||||||
|
|
||||||
# 0.37.0
|
# 0.37.0
|
||||||
|
|
||||||
|
@ -252,33 +252,6 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[pin_project(project = EitherFuture2Proj)]
|
|
||||||
#[derive(Debug, Copy, Clone)]
|
|
||||||
#[must_use = "futures do nothing unless polled"]
|
|
||||||
pub enum EitherFuture2<A, B> {
|
|
||||||
A(#[pin] A),
|
|
||||||
B(#[pin] B),
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<AFut, BFut, AItem, BItem, AError, BError> Future for EitherFuture2<AFut, BFut>
|
|
||||||
where
|
|
||||||
AFut: TryFuture<Ok = AItem, Error = AError>,
|
|
||||||
BFut: TryFuture<Ok = BItem, Error = BError>,
|
|
||||||
{
|
|
||||||
type Output = Result<EitherOutput<AItem, BItem>, Either<AError, BError>>;
|
|
||||||
|
|
||||||
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
|
|
||||||
match self.project() {
|
|
||||||
EitherFuture2Proj::A(a) => TryFuture::try_poll(a, cx)
|
|
||||||
.map_ok(EitherOutput::First)
|
|
||||||
.map_err(Either::Left),
|
|
||||||
EitherFuture2Proj::B(a) => TryFuture::try_poll(a, cx)
|
|
||||||
.map_ok(EitherOutput::Second)
|
|
||||||
.map_err(Either::Right),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub enum EitherName<A, B> {
|
pub enum EitherName<A, B> {
|
||||||
A(A),
|
A(A),
|
||||||
|
@ -19,7 +19,7 @@
|
|||||||
// DEALINGS IN THE SOFTWARE.
|
// DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
either::{EitherFuture2, EitherName, EitherOutput},
|
either::{EitherFuture, EitherName, EitherOutput},
|
||||||
upgrade::{InboundUpgrade, OutboundUpgrade, UpgradeInfo},
|
upgrade::{InboundUpgrade, OutboundUpgrade, UpgradeInfo},
|
||||||
};
|
};
|
||||||
use either::Either;
|
use either::Either;
|
||||||
@ -50,15 +50,15 @@ where
|
|||||||
{
|
{
|
||||||
type Output = EitherOutput<TA, TB>;
|
type Output = EitherOutput<TA, TB>;
|
||||||
type Error = Either<EA, EB>;
|
type Error = Either<EA, EB>;
|
||||||
type Future = EitherFuture2<A::Future, B::Future>;
|
type Future = EitherFuture<A::Future, B::Future>;
|
||||||
|
|
||||||
fn upgrade_inbound(self, sock: C, info: Self::Info) -> Self::Future {
|
fn upgrade_inbound(self, sock: C, info: Self::Info) -> Self::Future {
|
||||||
match (self, info) {
|
match (self, info) {
|
||||||
(Either::Left(a), EitherName::A(info)) => {
|
(Either::Left(a), EitherName::A(info)) => {
|
||||||
EitherFuture2::A(a.upgrade_inbound(sock, info))
|
EitherFuture::First(a.upgrade_inbound(sock, info))
|
||||||
}
|
}
|
||||||
(Either::Right(b), EitherName::B(info)) => {
|
(Either::Right(b), EitherName::B(info)) => {
|
||||||
EitherFuture2::B(b.upgrade_inbound(sock, info))
|
EitherFuture::Second(b.upgrade_inbound(sock, info))
|
||||||
}
|
}
|
||||||
_ => panic!("Invalid invocation of EitherUpgrade::upgrade_inbound"),
|
_ => panic!("Invalid invocation of EitherUpgrade::upgrade_inbound"),
|
||||||
}
|
}
|
||||||
@ -72,15 +72,15 @@ where
|
|||||||
{
|
{
|
||||||
type Output = EitherOutput<TA, TB>;
|
type Output = EitherOutput<TA, TB>;
|
||||||
type Error = Either<EA, EB>;
|
type Error = Either<EA, EB>;
|
||||||
type Future = EitherFuture2<A::Future, B::Future>;
|
type Future = EitherFuture<A::Future, B::Future>;
|
||||||
|
|
||||||
fn upgrade_outbound(self, sock: C, info: Self::Info) -> Self::Future {
|
fn upgrade_outbound(self, sock: C, info: Self::Info) -> Self::Future {
|
||||||
match (self, info) {
|
match (self, info) {
|
||||||
(Either::Left(a), EitherName::A(info)) => {
|
(Either::Left(a), EitherName::A(info)) => {
|
||||||
EitherFuture2::A(a.upgrade_outbound(sock, info))
|
EitherFuture::First(a.upgrade_outbound(sock, info))
|
||||||
}
|
}
|
||||||
(Either::Right(b), EitherName::B(info)) => {
|
(Either::Right(b), EitherName::B(info)) => {
|
||||||
EitherFuture2::B(b.upgrade_outbound(sock, info))
|
EitherFuture::Second(b.upgrade_outbound(sock, info))
|
||||||
}
|
}
|
||||||
_ => panic!("Invalid invocation of EitherUpgrade::upgrade_outbound"),
|
_ => panic!("Invalid invocation of EitherUpgrade::upgrade_outbound"),
|
||||||
}
|
}
|
||||||
|
@ -18,8 +18,9 @@
|
|||||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
// DEALINGS IN THE SOFTWARE.
|
// DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
|
use crate::either::EitherFuture;
|
||||||
use crate::{
|
use crate::{
|
||||||
either::{EitherFuture2, EitherName, EitherOutput},
|
either::{EitherName, EitherOutput},
|
||||||
upgrade::{InboundUpgrade, OutboundUpgrade, UpgradeInfo},
|
upgrade::{InboundUpgrade, OutboundUpgrade, UpgradeInfo},
|
||||||
};
|
};
|
||||||
use either::Either;
|
use either::Either;
|
||||||
@ -66,12 +67,12 @@ where
|
|||||||
{
|
{
|
||||||
type Output = EitherOutput<TA, TB>;
|
type Output = EitherOutput<TA, TB>;
|
||||||
type Error = Either<EA, EB>;
|
type Error = Either<EA, EB>;
|
||||||
type Future = EitherFuture2<A::Future, B::Future>;
|
type Future = EitherFuture<A::Future, B::Future>;
|
||||||
|
|
||||||
fn upgrade_inbound(self, sock: C, info: Self::Info) -> Self::Future {
|
fn upgrade_inbound(self, sock: C, info: Self::Info) -> Self::Future {
|
||||||
match info {
|
match info {
|
||||||
EitherName::A(info) => EitherFuture2::A(self.0.upgrade_inbound(sock, info)),
|
EitherName::A(info) => EitherFuture::First(self.0.upgrade_inbound(sock, info)),
|
||||||
EitherName::B(info) => EitherFuture2::B(self.1.upgrade_inbound(sock, info)),
|
EitherName::B(info) => EitherFuture::Second(self.1.upgrade_inbound(sock, info)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -83,12 +84,12 @@ where
|
|||||||
{
|
{
|
||||||
type Output = EitherOutput<TA, TB>;
|
type Output = EitherOutput<TA, TB>;
|
||||||
type Error = Either<EA, EB>;
|
type Error = Either<EA, EB>;
|
||||||
type Future = EitherFuture2<A::Future, B::Future>;
|
type Future = EitherFuture<A::Future, B::Future>;
|
||||||
|
|
||||||
fn upgrade_outbound(self, sock: C, info: Self::Info) -> Self::Future {
|
fn upgrade_outbound(self, sock: C, info: Self::Info) -> Self::Future {
|
||||||
match info {
|
match info {
|
||||||
EitherName::A(info) => EitherFuture2::A(self.0.upgrade_outbound(sock, info)),
|
EitherName::A(info) => EitherFuture::First(self.0.upgrade_outbound(sock, info)),
|
||||||
EitherName::B(info) => EitherFuture2::B(self.1.upgrade_outbound(sock, info)),
|
EitherName::B(info) => EitherFuture::Second(self.1.upgrade_outbound(sock, info)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user