Skip to content

Commit 37bfe6a

Browse files
authored
Merge pull request #732 from stuhood/stuhood/join-all-into-iter
Join all into iter
2 parents bf8578a + 194f198 commit 37bfe6a

File tree

2 files changed

+23
-14
lines changed

2 files changed

+23
-14
lines changed

src/future/join_all.rs

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,16 @@ enum ElemState<T> where T: Future {
1919
///
2020
/// This future is created with the `join_all` method.
2121
#[must_use = "futures do nothing unless polled"]
22-
pub struct JoinAll<I>
23-
where I: IntoIterator,
24-
I::Item: IntoFuture,
22+
pub struct JoinAll<Item>
23+
where Item: IntoFuture,
2524
{
26-
elems: Vec<ElemState<<I::Item as IntoFuture>::Future>>,
25+
elems: Vec<ElemState<<Item as IntoFuture>::Future>>,
2726
}
2827

2928
impl<I> fmt::Debug for JoinAll<I>
30-
where I: IntoIterator,
31-
I::Item: IntoFuture,
32-
<<I as IntoIterator>::Item as IntoFuture>::Future: fmt::Debug,
33-
<<I as IntoIterator>::Item as IntoFuture>::Item: fmt::Debug,
29+
where I: IntoFuture,
30+
<I as IntoFuture>::Future: fmt::Debug,
31+
<I as IntoFuture>::Item: fmt::Debug,
3432
{
3533
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
3634
fmt.debug_struct("JoinAll")
@@ -73,7 +71,7 @@ impl<I> fmt::Debug for JoinAll<I>
7371
/// x
7472
/// });
7573
/// ```
76-
pub fn join_all<I>(i: I) -> JoinAll<I>
74+
pub fn join_all<I>(i: I) -> JoinAll<I::Item>
7775
where I: IntoIterator,
7876
I::Item: IntoFuture,
7977
{
@@ -83,12 +81,11 @@ pub fn join_all<I>(i: I) -> JoinAll<I>
8381
JoinAll { elems: elems }
8482
}
8583

86-
impl<I> Future for JoinAll<I>
87-
where I: IntoIterator,
88-
I::Item: IntoFuture,
84+
impl<Item> Future for JoinAll<Item>
85+
where Item: IntoFuture,
8986
{
90-
type Item = Vec<<I::Item as IntoFuture>::Item>;
91-
type Error = <I::Item as IntoFuture>::Error;
87+
type Item = Vec<<Item as IntoFuture>::Item>;
88+
type Error = <Item as IntoFuture>::Error;
9289

9390

9491
fn poll(&mut self) -> Poll<Self::Item, Self::Error> {

tests/all.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,18 @@ fn collect_collects() {
251251
// TODO: needs more tests
252252
}
253253

254+
#[test]
255+
fn join_all_iter_lifetime() {
256+
// In futures-rs version 0.1, this function would fail to typecheck due to an overly
257+
// conservative type parameterization of `JoinAll`.
258+
fn sizes<'a>(bufs: Vec<&'a [u8]>) -> Box<Future<Item=Vec<usize>, Error=()> + 'static> {
259+
let iter = bufs.into_iter().map(|b| future::ok::<usize, ()>(b.len()));
260+
Box::new(join_all(iter))
261+
}
262+
263+
assert_done(|| sizes(vec![&[1,2,3], &[], &[0]]), Ok(vec![3, 0, 1]));
264+
}
265+
254266
#[test]
255267
fn select2() {
256268
fn d<T, U, E>(r: Result<(T, U), (E, U)>) -> Result<T, E> {

0 commit comments

Comments
 (0)