1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
use crate::IntoIterator;
use crate::Iterator;

/// Extend a collection with the contents of an iterator.

pub trait Extend<A> {
    /// Extends a collection with the contents of an iterator.
    async fn extend<T>(&mut self, iter: T)
    where
        T: IntoIterator<Item = A>;
}

#[cfg(any(feature = "alloc", feature = "std"))]
impl<T> Extend<T> for std::vec::Vec<T> {
    async fn extend<I: IntoIterator<Item = T>>(&mut self, iter: I) {
        let mut iter = iter.into_iter().await;
        self.reserve(iter.size_hint().1.unwrap_or_default());
        while let Some(item) = iter.next().await {
            self.push(item);
        }
    }
}