Skip to content

Commit

Permalink
Remove IntoFuture in trait bounds
Browse files Browse the repository at this point in the history
  • Loading branch information
Harry Barber committed Jul 19, 2023
1 parent a88e110 commit 60bcaed
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 23 deletions.
24 changes: 12 additions & 12 deletions futures-util/src/future/try_future/mod.rs
Expand Up @@ -89,15 +89,15 @@ delegate_all!(
delegate_all!(
/// Future for the [`inspect_ok`](super::TryFutureExt::inspect_ok) method.
InspectOk<Fut, F>(
Inspect<IntoFuture<Fut>, InspectOkFn<F>>
): Debug + Future + FusedFuture + New[|x: Fut, f: F| Inspect::new(IntoFuture::new(x), inspect_ok_fn(f))]
Inspect<Fut, InspectOkFn<F>>
): Debug + Future + FusedFuture + New[|x: Fut, f: F| Inspect::new(x, inspect_ok_fn(f))]
);

delegate_all!(
/// Future for the [`inspect_err`](super::TryFutureExt::inspect_err) method.
InspectErr<Fut, F>(
Inspect<IntoFuture<Fut>, InspectErrFn<F>>
): Debug + Future + FusedFuture + New[|x: Fut, f: F| Inspect::new(IntoFuture::new(x), inspect_err_fn(f))]
Inspect<Fut, InspectErrFn<F>>
): Debug + Future + FusedFuture + New[|x: Fut, f: F| Inspect::new(x, inspect_err_fn(f))]
);

#[allow(unreachable_pub)] // https://github.com/rust-lang/rust/issues/57411
Expand All @@ -106,29 +106,29 @@ pub use self::into_future::IntoFuture;
delegate_all!(
/// Future for the [`map_ok`](TryFutureExt::map_ok) method.
MapOk<Fut, F>(
Map<IntoFuture<Fut>, MapOkFn<F>>
): Debug + Future + FusedFuture + New[|x: Fut, f: F| Map::new(IntoFuture::new(x), map_ok_fn(f))]
Map<Fut, MapOkFn<F>>
): Debug + Future + FusedFuture + New[|x: Fut, f: F| Map::new(x, map_ok_fn(f))]
);

delegate_all!(
/// Future for the [`map_err`](TryFutureExt::map_err) method.
MapErr<Fut, F>(
Map<IntoFuture<Fut>, MapErrFn<F>>
): Debug + Future + FusedFuture + New[|x: Fut, f: F| Map::new(IntoFuture::new(x), map_err_fn(f))]
Map<Fut, MapErrFn<F>>
): Debug + Future + FusedFuture + New[|x: Fut, f: F| Map::new(x, map_err_fn(f))]
);

delegate_all!(
/// Future for the [`map_ok_or_else`](TryFutureExt::map_ok_or_else) method.
MapOkOrElse<Fut, F, G>(
Map<IntoFuture<Fut>, MapOkOrElseFn<F, G>>
): Debug + Future + FusedFuture + New[|x: Fut, f: F, g: G| Map::new(IntoFuture::new(x), map_ok_or_else_fn(f, g))]
Map<Fut, MapOkOrElseFn<F, G>>
): Debug + Future + FusedFuture + New[|x: Fut, f: F, g: G| Map::new(x, map_ok_or_else_fn(f, g))]
);

delegate_all!(
/// Future for the [`unwrap_or_else`](TryFutureExt::unwrap_or_else) method.
UnwrapOrElse<Fut, F>(
Map<IntoFuture<Fut>, UnwrapOrElseFn<F>>
): Debug + Future + FusedFuture + New[|x: Fut, f: F| Map::new(IntoFuture::new(x), unwrap_or_else_fn(f))]
Map<Fut, UnwrapOrElseFn<F>>
): Debug + Future + FusedFuture + New[|x: Fut, f: F| Map::new(x, unwrap_or_else_fn(f))]
);

impl<Fut: ?Sized + TryFuture> TryFutureExt for Fut {}
Expand Down
9 changes: 4 additions & 5 deletions futures-util/src/future/try_join_all.rs
Expand Up @@ -10,11 +10,10 @@ use core::mem;
use core::pin::Pin;
use core::task::{Context, Poll};

use super::{assert_future, join_all, IntoFuture, TryFuture, TryMaybeDone};
use super::{assert_future, join_all, TryFuture, TryMaybeDone};

#[cfg(not(futures_no_atomic_cas))]
use crate::stream::{FuturesOrdered, TryCollect, TryStreamExt};
use crate::TryFutureExt;

enum FinalState<E = ()> {
Pending,
Expand All @@ -36,11 +35,11 @@ where
F: TryFuture,
{
Small {
elems: Pin<Box<[TryMaybeDone<IntoFuture<F>>]>>,
elems: Pin<Box<[TryMaybeDone<F>]>>,
},
#[cfg(not(futures_no_atomic_cas))]
Big {
fut: TryCollect<FuturesOrdered<IntoFuture<F>>, Vec<F::Ok>>,
fut: TryCollect<FuturesOrdered<F>, Vec<F::Ok>>,
},
}

Expand Down Expand Up @@ -119,7 +118,7 @@ where
I: IntoIterator,
I::Item: TryFuture,
{
let iter = iter.into_iter().map(TryFutureExt::into_future);
let iter = iter.into_iter();

#[cfg(futures_no_atomic_cas)]
{
Expand Down
5 changes: 2 additions & 3 deletions futures-util/src/stream/try_stream/try_buffer_unordered.rs
@@ -1,4 +1,3 @@
use crate::future::{IntoFuture, TryFutureExt};
use crate::stream::{Fuse, FuturesUnordered, IntoStream, StreamExt};
use core::num::NonZeroUsize;
use core::pin::Pin;
Expand All @@ -19,7 +18,7 @@ pin_project! {
{
#[pin]
stream: Fuse<IntoStream<St>>,
in_progress_queue: FuturesUnordered<IntoFuture<St::Ok>>,
in_progress_queue: FuturesUnordered<St::Ok>,
max: Option<NonZeroUsize>,
}
}
Expand Down Expand Up @@ -54,7 +53,7 @@ where
// our queue of futures. Propagate errors from the stream immediately.
while this.max.map(|max| this.in_progress_queue.len() < max.get()).unwrap_or(true) {
match this.stream.as_mut().poll_next(cx)? {
Poll::Ready(Some(fut)) => this.in_progress_queue.push(fut.into_future()),
Poll::Ready(Some(fut)) => this.in_progress_queue.push(fut),
Poll::Ready(None) | Poll::Pending => break,
}
}
Expand Down
5 changes: 2 additions & 3 deletions futures-util/src/stream/try_stream/try_buffered.rs
@@ -1,4 +1,3 @@
use crate::future::{IntoFuture, TryFutureExt};
use crate::stream::{Fuse, FuturesOrdered, IntoStream, StreamExt};
use core::num::NonZeroUsize;
use core::pin::Pin;
Expand All @@ -20,7 +19,7 @@ pin_project! {
{
#[pin]
stream: Fuse<IntoStream<St>>,
in_progress_queue: FuturesOrdered<IntoFuture<St::Ok>>,
in_progress_queue: FuturesOrdered<St::Ok>,
max: Option<NonZeroUsize>,
}
}
Expand Down Expand Up @@ -55,7 +54,7 @@ where
// our queue of futures. Propagate errors from the stream immediately.
while this.max.map(|max| this.in_progress_queue.len() < max.get()).unwrap_or(true) {
match this.stream.as_mut().poll_next(cx)? {
Poll::Ready(Some(fut)) => this.in_progress_queue.push_back(fut.into_future()),
Poll::Ready(Some(fut)) => this.in_progress_queue.push_back(fut),
Poll::Ready(None) | Poll::Pending => break,
}
}
Expand Down

0 comments on commit 60bcaed

Please sign in to comment.