File tree 4 files changed +44
-1
lines changed
4 files changed +44
-1
lines changed Original file line number Diff line number Diff line change @@ -135,3 +135,25 @@ impl<T> Poll<Option<T>> {
135
135
#[ cfg_attr( not( bootstrap) , lang = "AsyncGenFinished" ) ]
136
136
pub const FINISHED : Self = Poll :: Ready ( None ) ;
137
137
}
138
+
139
+ /// Convert something into an async iterator
140
+ #[ unstable( feature = "async_iterator" , issue = "79024" ) ]
141
+ pub trait IntoAsyncIterator {
142
+ /// The type of the item yielded by the iterator
143
+ type Item ;
144
+ /// The type of the resulting iterator
145
+ type IntoAsyncIter : AsyncIterator < Item = Self :: Item > ;
146
+
147
+ /// Converts `self` into an async iterator
148
+ fn into_async_iter ( self ) -> Self :: IntoAsyncIter ;
149
+ }
150
+
151
+ #[ unstable( feature = "async_iterator" , issue = "79024" ) ]
152
+ impl < I : AsyncIterator > IntoAsyncIterator for I {
153
+ type Item = I :: Item ;
154
+ type IntoAsyncIter = I ;
155
+
156
+ fn into_async_iter ( self ) -> Self :: IntoAsyncIter {
157
+ self
158
+ }
159
+ }
Original file line number Diff line number Diff line change 124
124
mod async_iter;
125
125
mod from_iter;
126
126
127
- pub use async_iter:: AsyncIterator ;
127
+ pub use async_iter:: { AsyncIterator , IntoAsyncIterator } ;
128
128
pub use from_iter:: { from_iter, FromIter } ;
Original file line number Diff line number Diff line change
1
+ use core:: async_iter:: { self , AsyncIterator , IntoAsyncIterator } ;
2
+ use core:: pin:: pin;
3
+ use core:: task:: Poll ;
4
+
5
+ #[ test]
6
+ fn into_async_iter ( ) {
7
+ let async_iter = async_iter:: from_iter ( 0 ..3 ) ;
8
+ let mut async_iter = pin ! ( async_iter. into_async_iter( ) ) ;
9
+
10
+ let waker = core:: task:: Waker :: noop ( ) ;
11
+ let mut cx = & mut core:: task:: Context :: from_waker ( & waker) ;
12
+
13
+ assert_eq ! ( async_iter. as_mut( ) . poll_next( & mut cx) , Poll :: Ready ( Some ( 0 ) ) ) ;
14
+ assert_eq ! ( async_iter. as_mut( ) . poll_next( & mut cx) , Poll :: Ready ( Some ( 1 ) ) ) ;
15
+ assert_eq ! ( async_iter. as_mut( ) . poll_next( & mut cx) , Poll :: Ready ( Some ( 2 ) ) ) ;
16
+ assert_eq ! ( async_iter. as_mut( ) . poll_next( & mut cx) , Poll :: Ready ( None ) ) ;
17
+ }
Original file line number Diff line number Diff line change 4
4
#![ feature( array_windows) ]
5
5
#![ feature( ascii_char) ]
6
6
#![ feature( ascii_char_variants) ]
7
+ #![ feature( async_iter_from_iter) ]
8
+ #![ feature( async_iterator) ]
7
9
#![ feature( bigint_helper_methods) ]
8
10
#![ feature( cell_update) ]
9
11
#![ feature( const_align_offset) ]
55
57
#![ feature( maybe_uninit_write_slice) ]
56
58
#![ feature( maybe_uninit_uninit_array_transpose) ]
57
59
#![ feature( min_specialization) ]
60
+ #![ feature( noop_waker) ]
58
61
#![ feature( numfmt) ]
59
62
#![ feature( num_midpoint) ]
60
63
#![ feature( isqrt) ]
@@ -126,6 +129,7 @@ mod any;
126
129
mod array;
127
130
mod ascii;
128
131
mod asserting;
132
+ mod async_iter;
129
133
mod atomic;
130
134
mod bool;
131
135
mod cell;
You can’t perform that action at this time.
0 commit comments