Skip to content

Commit

Permalink
add FutureGroup::extend
Browse files Browse the repository at this point in the history
reimplement `FutureGroup::from_iter` in terms of `extend`
  • Loading branch information
soooch committed Apr 23, 2024
1 parent 1eb7a23 commit de8a750
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/future/future_group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -415,14 +415,22 @@ impl<F: Future> Stream for FutureGroup<F> {
}
}

impl<F: Future> FromIterator<F> for FutureGroup<F> {
fn from_iter<T: IntoIterator<Item = F>>(iter: T) -> Self {
impl<F: Future> Extend<F> for FutureGroup<F> {
fn extend<T: IntoIterator<Item = F>>(&mut self, iter: T) {
let iter = iter.into_iter();
let len = iter.size_hint().1.unwrap_or_default();
let mut this = Self::with_capacity(len);
self.reserve(len);

for future in iter {
this.insert(future);
self.insert(future);
}
}
}

impl<F: Future> FromIterator<F> for FutureGroup<F> {
fn from_iter<T: IntoIterator<Item = F>>(iter: T) -> Self {
let mut this = Self::new();
this.extend(iter);
this
}
}
Expand Down

0 comments on commit de8a750

Please sign in to comment.