Skip to content

Commit 149e1b9

Browse files
committed
Remove futures_[un]ordered functions
1 parent 6e96a85 commit 149e1b9

File tree

6 files changed

+24
-63
lines changed

6 files changed

+24
-63
lines changed

futures-util/src/stream/futures_ordered.rs

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@ impl<T> Future for OrderWrapper<T>
8585
/// some of the later futures have already completed.
8686
///
8787
/// Note that you can create a ready-made `FuturesOrdered` via the
88-
/// `futures_ordered` function in the `stream` module, or you can start with an
89-
/// empty queue with the `FuturesOrdered::new` constructor.
88+
/// [`collect`](Iterator::collect) method, or you can start with an empty queue
89+
/// with the `FuturesOrdered::new` constructor.
9090
#[must_use = "streams do nothing unless polled"]
9191
pub struct FuturesOrdered<T: Future> {
9292
in_progress_queue: FuturesUnordered<OrderWrapper<T>>,
@@ -97,25 +97,6 @@ pub struct FuturesOrdered<T: Future> {
9797

9898
impl<T: Future> Unpin for FuturesOrdered<T> {}
9999

100-
/// Converts a list of futures into a `Stream` of results from the futures.
101-
///
102-
/// This function will take a list of futures (e.g. a vector, an iterator,
103-
/// etc), and return a stream. The stream will yield items as they become
104-
/// available on the futures internally, in the order that their originating
105-
/// futures were submitted to the queue. If the futures complete out of order,
106-
/// items will be stored internally within `FuturesOrdered` until all preceding
107-
/// items have been yielded.
108-
///
109-
/// Note that the returned queue can also be used to dynamically push more
110-
/// futures into the queue as they become available.
111-
pub fn futures_ordered<I>(futures: I) -> FuturesOrdered<I::Item>
112-
where
113-
I: IntoIterator,
114-
I::Item: Future,
115-
{
116-
futures.into_iter().collect()
117-
}
118-
119100
impl<Fut: Future> FuturesOrdered<Fut> {
120101
/// Constructs a new, empty `FuturesOrdered`
121102
///

futures-util/src/stream/futures_unordered/mod.rs

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use alloc::sync::{Arc, Weak};
1919
mod abort;
2020

2121
mod iter;
22-
use self::iter::{IterMut, IterPinMut};
22+
pub use self::iter::{IterMut, IterPinMut};
2323

2424
mod task;
2525
use self::task::Task;
@@ -51,8 +51,8 @@ const TERMINATED_SENTINEL_LENGTH: usize = usize::max_value();
5151
/// wake-ups for new futures.
5252
///
5353
/// Note that you can create a ready-made [`FuturesUnordered`] via the
54-
/// [`futures_unordered`](futures_unordered()) function, or you can start with
55-
/// an empty set with the [`FuturesUnordered::new`] constructor.
54+
/// [`collect`](Iterator::collect) method, or you can start with an empty set
55+
/// with the [`FuturesUnordered::new`] constructor.
5656
#[must_use = "streams do nothing unless polled"]
5757
pub struct FuturesUnordered<Fut> {
5858
ready_to_run_queue: Arc<ReadyToRunQueue<Fut>>,
@@ -469,25 +469,6 @@ impl<Fut: Future> FromIterator<Fut> for FuturesUnordered<Fut> {
469469
}
470470
}
471471

472-
/// Converts a list of futures into a [`Stream`] of outputs from the futures.
473-
///
474-
/// This function will take a list of futures (e.g. a [`Vec`], an [`Iterator`],
475-
/// etc), and return a stream. The stream will yield items as they become
476-
/// available on the futures internally, in the order that they become
477-
/// available. This function is similar to
478-
/// [`buffer_unordered`](super::StreamExt::buffer_unordered) in that it may
479-
/// return items in a different order than in the list specified.
480-
///
481-
/// Note that the returned set can also be used to dynamically push more
482-
/// futures into the set as they become available.
483-
pub fn futures_unordered<I>(futures: I) -> FuturesUnordered<I::Item>
484-
where
485-
I: IntoIterator,
486-
I::Item: Future,
487-
{
488-
futures.into_iter().collect()
489-
}
490-
491472
impl<Fut: Future> FusedStream for FuturesUnordered<Fut> {
492473
fn is_terminated(&self) -> bool {
493474
self.len == TERMINATED_SENTINEL_LENGTH

futures-util/src/stream/mod.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,12 +123,13 @@ cfg_target_has_atomic! {
123123
#[cfg(feature = "alloc")]
124124
mod futures_ordered;
125125
#[cfg(feature = "alloc")]
126-
pub use self::futures_ordered::{futures_ordered, FuturesOrdered};
126+
pub use self::futures_ordered::FuturesOrdered;
127127

128128
#[cfg(feature = "alloc")]
129-
mod futures_unordered;
129+
pub mod futures_unordered;
130130
#[cfg(feature = "alloc")]
131-
pub use self::futures_unordered::{futures_unordered, FuturesUnordered};
131+
#[doc(inline)]
132+
pub use self::futures_unordered::FuturesUnordered;
132133

133134
#[cfg(feature = "alloc")]
134135
mod split;

futures/src/lib.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -322,10 +322,8 @@ pub mod stream {
322322
//! asynchronously produce a sequence of values.
323323
//! - The [`StreamExt`](crate::stream::StreamExt) trait, which provides
324324
//! adapters for chaining and composing streams.
325-
//! - Top-level stream contructors like [`iter_ok`](crate::stream::iter)
326-
//! which creates a stream from an iterator, and
327-
//! [`futures_unordered`](crate::stream::futures_unordered()), which
328-
//! constructs a stream from a collection of futures.
325+
//! - Top-level stream contructors like [`iter`](crate::stream::iter)
326+
//! which creates a stream from an iterator.
329327
330328
pub use futures_core::stream::{
331329
Stream, TryStream, FusedStream,
@@ -358,7 +356,7 @@ pub mod stream {
358356
)]
359357
#[cfg(feature = "alloc")]
360358
pub use futures_util::stream::{
361-
futures_ordered, FuturesOrdered,
359+
FuturesOrdered,
362360
futures_unordered, FuturesUnordered,
363361

364362
// For StreamExt:

futures/tests/futures_ordered.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use futures::channel::oneshot;
44
use futures::executor::{block_on, block_on_stream};
55
use futures::future::{self, FutureExt, FutureObj};
6-
use futures::stream::{StreamExt, futures_ordered, FuturesOrdered};
6+
use futures::stream::{StreamExt, FuturesOrdered};
77
use futures_test::task::noop_waker_ref;
88

99
#[test]
@@ -12,7 +12,7 @@ fn works_1() {
1212
let (b_tx, b_rx) = oneshot::channel::<i32>();
1313
let (c_tx, c_rx) = oneshot::channel::<i32>();
1414

15-
let mut stream = futures_ordered(vec![a_rx, b_rx, c_rx]);
15+
let mut stream = vec![a_rx, b_rx, c_rx].into_iter().collect::<FuturesOrdered<_>>();
1616

1717
b_tx.send(99).unwrap();
1818
assert!(stream.poll_next_unpin(&noop_waker_ref()).is_pending());
@@ -33,10 +33,10 @@ fn works_2() {
3333
let (b_tx, b_rx) = oneshot::channel::<i32>();
3434
let (c_tx, c_rx) = oneshot::channel::<i32>();
3535

36-
let mut stream = futures_ordered(vec![
36+
let mut stream = vec![
3737
FutureObj::new(Box::new(a_rx)),
3838
FutureObj::new(Box::new(b_rx.join(c_rx).map(|(a, b)| Ok(a? + b?)))),
39-
]);
39+
].into_iter().collect::<FuturesOrdered<_>>();
4040

4141
let lw = &noop_waker_ref();
4242
a_tx.send(33).unwrap();

futures/tests/futures_unordered.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use futures::channel::oneshot;
44
use futures::executor::{block_on, block_on_stream};
55
use futures::future::{self, FutureExt, FutureObj};
6-
use futures::stream::{StreamExt, futures_unordered, FuturesUnordered};
6+
use futures::stream::{StreamExt, FuturesUnordered};
77
use futures::task::Poll;
88
use futures_test::{assert_stream_done, assert_stream_next};
99
use futures_test::future::FutureTestExt;
@@ -16,7 +16,7 @@ fn works_1() {
1616
let (b_tx, b_rx) = oneshot::channel::<i32>();
1717
let (c_tx, c_rx) = oneshot::channel::<i32>();
1818

19-
let mut iter = block_on_stream(futures_unordered(vec![a_rx, b_rx, c_rx]));
19+
let mut iter = block_on_stream(vec![a_rx, b_rx, c_rx].into_iter().collect::<FuturesUnordered<_>>());
2020

2121
b_tx.send(99).unwrap();
2222
assert_eq!(Some(Ok(99)), iter.next());
@@ -34,10 +34,10 @@ fn works_2() {
3434
let (b_tx, b_rx) = oneshot::channel::<i32>();
3535
let (c_tx, c_rx) = oneshot::channel::<i32>();
3636

37-
let mut stream = futures_unordered(vec![
37+
let mut stream = vec![
3838
FutureObj::new(Box::new(a_rx)),
3939
FutureObj::new(Box::new(b_rx.join(c_rx).map(|(a, b)| Ok(a? + b?)))),
40-
]);
40+
].into_iter().collect::<FuturesUnordered<_>>();
4141

4242
a_tx.send(9).unwrap();
4343
b_tx.send(10).unwrap();
@@ -91,7 +91,7 @@ fn iter_mut_cancel() {
9191
let (b_tx, b_rx) = oneshot::channel::<i32>();
9292
let (c_tx, c_rx) = oneshot::channel::<i32>();
9393

94-
let mut stream = futures_unordered(vec![a_rx, b_rx, c_rx]);
94+
let mut stream = vec![a_rx, b_rx, c_rx].into_iter().collect::<FuturesUnordered<_>>();
9595

9696
for rx in stream.iter_mut() {
9797
rx.close();
@@ -111,11 +111,11 @@ fn iter_mut_cancel() {
111111

112112
#[test]
113113
fn iter_mut_len() {
114-
let mut stream = futures_unordered(vec![
114+
let mut stream = vec![
115115
future::empty::<()>(),
116116
future::empty::<()>(),
117117
future::empty::<()>()
118-
]);
118+
].into_iter().collect::<FuturesUnordered<_>>();
119119

120120
let mut iter_mut = stream.iter_mut();
121121
assert_eq!(iter_mut.len(), 3);
@@ -133,7 +133,7 @@ fn futures_not_moved_after_poll() {
133133
// Future that will be ready after being polled twice,
134134
// asserting that it does not move.
135135
let fut = future::ready(()).pending_once().assert_unmoved();
136-
let mut stream = futures_unordered(vec![fut; 3]);
136+
let mut stream = vec![fut; 3].into_iter().collect::<FuturesUnordered<_>>();
137137
assert_stream_next!(stream, ());
138138
assert_stream_next!(stream, ());
139139
assert_stream_next!(stream, ());

0 commit comments

Comments
 (0)