From 84f6845bf2238bd05eda9afd556f4a6fed42b60d Mon Sep 17 00:00:00 2001 From: Nylonicious <50183564+nylonicious@users.noreply.github.com> Date: Tue, 24 Aug 2021 13:21:02 +0200 Subject: [PATCH] stream: impl FromIterator for StreamMap (#4052) --- tokio-stream/src/stream_map.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tokio-stream/src/stream_map.rs b/tokio-stream/src/stream_map.rs index 9dc529ac0..80a521ee1 100644 --- a/tokio-stream/src/stream_map.rs +++ b/tokio-stream/src/stream_map.rs @@ -568,6 +568,23 @@ where } } +impl std::iter::FromIterator<(K, V)> for StreamMap +where + K: Hash + Eq, +{ + fn from_iter>(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;