diff options
author | Matthias Beyer <mail@beyermatthias.de> | 2020-11-07 11:04:01 +0100 |
---|---|---|
committer | Matthias Beyer <mail@beyermatthias.de> | 2020-11-07 11:04:51 +0100 |
commit | f6b22f5ec1bf09a1d14b044cb9a0e833406c9698 (patch) | |
tree | f68b8de1e5ef0779ae3f09fcca578aa6c58bb361 /tokio/src/stream/mod.rs | |
parent | a43ec09b55363374221aa3214fe0cec3d6712b6c (diff) |
Add IntoStream for all Iterator<_>iter-into-stream
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
Diffstat (limited to 'tokio/src/stream/mod.rs')
-rw-r--r-- | tokio/src/stream/mod.rs | 12 |
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>), |