summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2020-11-07 11:04:01 +0100
committerMatthias Beyer <mail@beyermatthias.de>2020-11-07 11:04:51 +0100
commitf6b22f5ec1bf09a1d14b044cb9a0e833406c9698 (patch)
treef68b8de1e5ef0779ae3f09fcca578aa6c58bb361
parenta43ec09b55363374221aa3214fe0cec3d6712b6c (diff)
downloadtokio-iter-into-stream.tar.gz
tokio-iter-into-stream.tar.xz
Add IntoStream for all Iterator<_>iter-into-stream
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
-rw-r--r--tokio/src/stream/mod.rs12
1 files changed, 12 insertions, 0 deletions
diff --git a/tokio/src/stream/mod.rs b/tokio/src/stream/mod.rs
index 6bf42324..f14e59f8 100644
--- a/tokio/src/stream/mod.rs
+++ b/tokio/src/stream/mod.rs
@@ -926,6 +926,18 @@ pub trait StreamExt: Stream {
impl<St: ?Sized> StreamExt for St where St: Stream {}
+pub trait IntoStream<T>: std::iter::Iterator<Item = T> + Sized {
+ fn into_stream(self) -> Iter<Self>;
+}
+
+impl<I, T> IntoStream<T> for I
+ where I: std::iter::Iterator<Item = T> + Sized
+{
+ fn into_stream(self) -> Iter<Self> {
+ iter(self)
+ }
+}
+
/// Merge the size hints from two streams.
fn merge_size_hints(
(left_low, left_high): (usize, Option<usize>),