From 09b6dfe5b8f41f3edfa7aa69f0450b7975b6004c Mon Sep 17 00:00:00 2001 From: Yosh Date: Wed, 5 Apr 2023 14:55:03 +0200 Subject: [PATCH] impl chain,zip on stream ext --- src/stream/stream_ext.rs | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/src/stream/stream_ext.rs b/src/stream/stream_ext.rs index fcf25fb..3321735 100644 --- a/src/stream/stream_ext.rs +++ b/src/stream/stream_ext.rs @@ -1,7 +1,7 @@ use crate::stream::{IntoStream, Merge}; use futures_core::Stream; -use super::merge::tuple::Merge2; +use super::{chain::tuple::Chain2, merge::tuple::Merge2, zip::tuple::Zip2, Chain, Zip}; /// An extension trait for the `Stream` trait. pub trait StreamExt: Stream { @@ -10,6 +10,18 @@ pub trait StreamExt: Stream { where Self: Stream + Sized, S2: IntoStream; + + /// Takes two streams and creates a new stream over all in sequence + fn chain(self, other: S2) -> Chain2 + where + Self: Stream + Sized, + S2: IntoStream; + + /// ‘Zips up’ multiple streams into a single stream of pairs. + fn zip(self, other: S2) -> Zip2 + where + Self: Stream + Sized, + S2: IntoStream; } impl StreamExt for S1 @@ -23,4 +35,22 @@ where { Merge::merge((self, other)) } + + fn chain(self, other: S2) -> Chain2 + where + Self: Stream + Sized, + S2: IntoStream, + { + // TODO(yosh): fix the bounds on the tuple impl + Chain::chain((self, other.into_stream())) + } + + fn zip(self, other: S2) -> Zip2 + where + Self: Stream + Sized, + S2: IntoStream, + { + // TODO(yosh): fix the bounds on the tuple impl + Zip::zip((self, other.into_stream())) + } }