@@ -11,8 +11,7 @@ use futures_core::task::{Context, Poll};
11
11
use pin_project_lite:: pin_project;
12
12
13
13
use 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 } ;
16
15
17
16
pin_project ! {
18
17
/// An unbounded set of streams
@@ -71,27 +70,17 @@ impl<St: Stream + Unpin> SelectAll<St> {
71
70
self . inner . push ( stream. into_future ( ) ) ;
72
71
}
73
72
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 ( ) )
77
76
}
78
77
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 ( ) )
82
81
}
83
82
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.
95
84
pub fn clear ( & mut self ) {
96
85
self . inner . clear ( )
97
86
}
@@ -139,7 +128,7 @@ impl<St: Stream + Unpin> FusedStream for SelectAll<St> {
139
128
/// streams internally, in the order they become available.
140
129
///
141
130
/// 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.
143
132
///
144
133
/// This function is only available when the `std` or `alloc` feature of this
145
134
/// library is activated, and it is activated by default.
@@ -172,28 +161,94 @@ impl<St: Stream + Unpin> Extend<St> for SelectAll<St> {
172
161
}
173
162
174
163
impl < 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 > ;
177
166
178
167
fn into_iter ( self ) -> Self :: IntoIter {
179
- self . inner . into_iter ( )
168
+ IntoIter ( self . inner . into_iter ( ) )
180
169
}
181
170
}
182
171
183
172
impl < ' 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 > ;
186
175
187
176
fn into_iter ( self ) -> Self :: IntoIter {
188
177
self . iter ( )
189
178
}
190
179
}
191
180
192
181
impl < ' 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 > ;
195
184
196
185
fn into_iter ( self ) -> Self :: IntoIter {
197
186
self . iter_mut ( )
198
187
}
199
188
}
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