stream: impl FromIterator for StreamMap (#4052)

This commit is contained in:
Nylonicious 2021-08-24 13:21:02 +02:00 committed by GitHub
parent 2bc9a42d2b
commit 84f6845bf2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -568,6 +568,23 @@ where
}
}
impl<K, V> std::iter::FromIterator<(K, V)> for StreamMap<K, V>
where
K: Hash + Eq,
{
fn from_iter<T: IntoIterator<Item = (K, V)>>(iter: T) -> Self {
let iterator = iter.into_iter();
let (lower_bound, _) = iterator.size_hint();
let mut stream_map = Self::with_capacity(lower_bound);
for (key, value) in iterator {
stream_map.insert(key, value);
}
stream_map
}
}
mod rand {
use std::cell::Cell;