Skip to content

Commit de8a750

Browse files
committed
add FutureGroup::extend
reimplement `FutureGroup::from_iter` in terms of `extend`
1 parent 1eb7a23 commit de8a750

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

src/future/future_group.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -415,14 +415,22 @@ impl<F: Future> Stream for FutureGroup<F> {
415415
}
416416
}
417417

418-
impl<F: Future> FromIterator<F> for FutureGroup<F> {
419-
fn from_iter<T: IntoIterator<Item = F>>(iter: T) -> Self {
418+
impl<F: Future> Extend<F> for FutureGroup<F> {
419+
fn extend<T: IntoIterator<Item = F>>(&mut self, iter: T) {
420420
let iter = iter.into_iter();
421421
let len = iter.size_hint().1.unwrap_or_default();
422-
let mut this = Self::with_capacity(len);
422+
self.reserve(len);
423+
423424
for future in iter {
424-
this.insert(future);
425+
self.insert(future);
425426
}
427+
}
428+
}
429+
430+
impl<F: Future> FromIterator<F> for FutureGroup<F> {
431+
fn from_iter<T: IntoIterator<Item = F>>(iter: T) -> Self {
432+
let mut this = Self::new();
433+
this.extend(iter);
426434
this
427435
}
428436
}

0 commit comments

Comments
 (0)