async_std/collections/hash_map/
extend.rs1use std::collections::HashMap;
2use std::hash::{BuildHasher, Hash};
3use std::pin::Pin;
4
5use crate::prelude::*;
6use crate::stream::{self, IntoStream};
7
8impl<K, V, H> stream::Extend<(K, V)> for HashMap<K, V, H>
9where
10 K: Eq + Hash + Send,
11 V: Send,
12 H: BuildHasher + Default + Send,
13{
14 fn extend<'a, S: IntoStream<Item = (K, V)> + 'a>(
15 &'a mut self,
16 stream: S,
17 ) -> Pin<Box<dyn Future<Output = ()> + 'a + Send>>
18 where
19 <S as IntoStream>::IntoStream: Send,
20 {
21 let stream = stream.into_stream();
22
23 let additional = if self.is_empty() {
31 stream.size_hint().0
32 } else {
33 (stream.size_hint().0 + 1) / 2
34 };
35 self.reserve(additional);
36
37 Box::pin(stream.for_each(move |(k, v)| {
38 self.insert(k, v);
39 }))
40 }
41}