@@ -11,8 +11,7 @@ use futures_core::task::{Context, Poll};
1111use pin_project_lite:: pin_project;
1212
1313use super :: assert_stream;
14- use crate :: stream:: futures_unordered:: { IntoIter , Iter , IterMut , IterPinMut , IterPinRef } ;
15- use crate :: stream:: { FuturesUnordered , StreamExt , StreamFuture } ;
14+ use crate :: stream:: { futures_unordered, FuturesUnordered , StreamExt , StreamFuture } ;
1615
1716pin_project ! {
1817 /// An unbounded set of streams
@@ -71,27 +70,17 @@ impl<St: Stream + Unpin> SelectAll<St> {
7170 self . inner . push ( stream. into_future ( ) ) ;
7271 }
7372
74- /// Returns an iterator that allows inspecting each future in the set.
75- pub fn iter ( & self ) -> Iter < ' _ , StreamFuture < St > > {
76- self . inner . iter ( )
73+ /// Returns an iterator that allows inspecting each stream in the set.
74+ pub fn iter ( & self ) -> Iter < ' _ , St > {
75+ Iter ( self . inner . iter ( ) )
7776 }
7877
79- /// Returns an iterator that allows inspecting each future in the set.
80- pub fn iter_pin_ref ( self : Pin < & ' _ Self > ) -> IterPinRef < ' _ , StreamFuture < St > > {
81- self . project_ref ( ) . inner . iter_pin_ref ( )
78+ /// Returns an iterator that allows modifying each stream in the set.
79+ pub fn iter_mut ( & mut self ) -> IterMut < ' _ , St > {
80+ IterMut ( self . inner . iter_mut ( ) )
8281 }
8382
84- /// Returns an iterator that allows modifying each future in the set.
85- pub fn iter_mut ( & mut self ) -> IterMut < ' _ , StreamFuture < St > > {
86- self . inner . iter_mut ( )
87- }
88-
89- /// Returns an iterator that allows modifying each future in the set.
90- pub fn iter_pin_mut ( self : Pin < & mut Self > ) -> IterPinMut < ' _ , StreamFuture < St > > {
91- self . project ( ) . inner . iter_pin_mut ( )
92- }
93-
94- /// Clears the set, removing all futures.
83+ /// Clears the set, removing all streams.
9584 pub fn clear ( & mut self ) {
9685 self . inner . clear ( )
9786 }
@@ -139,7 +128,7 @@ impl<St: Stream + Unpin> FusedStream for SelectAll<St> {
139128/// streams internally, in the order they become available.
140129///
141130/// Note that the returned set can also be used to dynamically push more
142- /// futures into the set as they become available.
131+ /// streams into the set as they become available.
143132///
144133/// This function is only available when the `std` or `alloc` feature of this
145134/// library is activated, and it is activated by default.
@@ -172,28 +161,94 @@ impl<St: Stream + Unpin> Extend<St> for SelectAll<St> {
172161}
173162
174163impl < St : Stream + Unpin > IntoIterator for SelectAll < St > {
175- type Item = StreamFuture < St > ;
176- type IntoIter = IntoIter < StreamFuture < St > > ;
164+ type Item = St ;
165+ type IntoIter = IntoIter < St > ;
177166
178167 fn into_iter ( self ) -> Self :: IntoIter {
179- self . inner . into_iter ( )
168+ IntoIter ( self . inner . into_iter ( ) )
180169 }
181170}
182171
183172impl < ' a , St : Stream + Unpin > IntoIterator for & ' a SelectAll < St > {
184- type Item = & ' a StreamFuture < St > ;
185- type IntoIter = Iter < ' a , StreamFuture < St > > ;
173+ type Item = & ' a St ;
174+ type IntoIter = Iter < ' a , St > ;
186175
187176 fn into_iter ( self ) -> Self :: IntoIter {
188177 self . iter ( )
189178 }
190179}
191180
192181impl < ' a , St : Stream + Unpin > IntoIterator for & ' a mut SelectAll < St > {
193- type Item = & ' a mut StreamFuture < St > ;
194- type IntoIter = IterMut < ' a , StreamFuture < St > > ;
182+ type Item = & ' a mut St ;
183+ type IntoIter = IterMut < ' a , St > ;
195184
196185 fn into_iter ( self ) -> Self :: IntoIter {
197186 self . iter_mut ( )
198187 }
199188}
189+
190+ /// Immutable iterator over all streams in the unordered set.
191+ #[ derive( Debug ) ]
192+ pub struct Iter < ' a , St : Unpin > ( futures_unordered:: Iter < ' a , StreamFuture < St > > ) ;
193+
194+ /// Mutable iterator over all streams in the unordered set.
195+ #[ derive( Debug ) ]
196+ pub struct IterMut < ' a , St : Unpin > ( futures_unordered:: IterMut < ' a , StreamFuture < St > > ) ;
197+
198+ /// Owned iterator over all streams in the unordered set.
199+ #[ derive( Debug ) ]
200+ pub struct IntoIter < St : Unpin > ( futures_unordered:: IntoIter < StreamFuture < St > > ) ;
201+
202+ impl < ' a , St : Stream + Unpin > Iterator for Iter < ' a , St > {
203+ type Item = & ' a St ;
204+
205+ fn next ( & mut self ) -> Option < Self :: Item > {
206+ let st = self . 0 . next ( ) ?;
207+ let next = st. get_ref ( ) ;
208+ // This should always be true because FuturesUnordered removes completed futures.
209+ debug_assert ! ( next. is_some( ) ) ;
210+ next
211+ }
212+
213+ fn size_hint ( & self ) -> ( usize , Option < usize > ) {
214+ self . 0 . size_hint ( )
215+ }
216+ }
217+
218+ impl < St : Stream + Unpin > ExactSizeIterator for Iter < ' _ , St > { }
219+
220+ impl < ' a , St : Stream + Unpin > Iterator for IterMut < ' a , St > {
221+ type Item = & ' a mut St ;
222+
223+ fn next ( & mut self ) -> Option < Self :: Item > {
224+ let st = self . 0 . next ( ) ?;
225+ let next = st. get_mut ( ) ;
226+ // This should always be true because FuturesUnordered removes completed futures.
227+ debug_assert ! ( next. is_some( ) ) ;
228+ next
229+ }
230+
231+ fn size_hint ( & self ) -> ( usize , Option < usize > ) {
232+ self . 0 . size_hint ( )
233+ }
234+ }
235+
236+ impl < St : Stream + Unpin > ExactSizeIterator for IterMut < ' _ , St > { }
237+
238+ impl < St : Stream + Unpin > Iterator for IntoIter < St > {
239+ type Item = St ;
240+
241+ fn next ( & mut self ) -> Option < Self :: Item > {
242+ let st = self . 0 . next ( ) ?;
243+ let next = st. into_inner ( ) ;
244+ // This should always be true because FuturesUnordered removes completed futures.
245+ debug_assert ! ( next. is_some( ) ) ;
246+ next
247+ }
248+
249+ fn size_hint ( & self ) -> ( usize , Option < usize > ) {
250+ self . 0 . size_hint ( )
251+ }
252+ }
253+
254+ impl < St : Stream + Unpin > ExactSizeIterator for IntoIter < St > { }
0 commit comments