mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-09-08 00:00:13 +02:00
stream: impl FromIterator for StreamMap (#4052)
This commit is contained in:
@@ -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 {
|
mod rand {
|
||||||
use std::cell::Cell;
|
use std::cell::Cell;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user