File tree Expand file tree Collapse file tree 4 files changed +44
-1
lines changed Expand file tree Collapse file tree 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>> {
135135 #[ cfg_attr( not( bootstrap) , lang = "AsyncGenFinished" ) ]
136136 pub const FINISHED : Self = Poll :: Ready ( None ) ;
137137}
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 124124mod async_iter;
125125mod from_iter;
126126
127- pub use async_iter:: AsyncIterator ;
127+ pub use async_iter:: { AsyncIterator , IntoAsyncIterator } ;
128128pub 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 44#![ feature( array_windows) ]
55#![ feature( ascii_char) ]
66#![ feature( ascii_char_variants) ]
7+ #![ feature( async_iter_from_iter) ]
8+ #![ feature( async_iterator) ]
79#![ feature( bigint_helper_methods) ]
810#![ feature( cell_update) ]
911#![ feature( const_align_offset) ]
5557#![ feature( maybe_uninit_write_slice) ]
5658#![ feature( maybe_uninit_uninit_array_transpose) ]
5759#![ feature( min_specialization) ]
60+ #![ feature( noop_waker) ]
5861#![ feature( numfmt) ]
5962#![ feature( num_midpoint) ]
6063#![ feature( isqrt) ]
@@ -126,6 +129,7 @@ mod any;
126129mod array;
127130mod ascii;
128131mod asserting;
132+ mod async_iter;
129133mod atomic;
130134mod bool;
131135mod cell;
You can’t perform that action at this time.
0 commit comments