mirror of
https://github.com/tokio-rs/tokio.git
synced 2025-09-28 12:10:37 +00:00
stream: impl FromIterator for StreamMap (#4052)
This commit is contained in:
parent
2bc9a42d2b
commit
84f6845bf2
@ -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;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user