File tree Expand file tree Collapse file tree 4 files changed +45
-1
lines changed Expand file tree Collapse file tree 4 files changed +45
-1
lines changed Original file line number Diff line number Diff line change @@ -135,3 +135,26 @@ impl<T> Poll<Option<T>> {
135135 #[ 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+ #[ cfg_attr( not( bootstrap) , lang = "into_async_iter_into_iter" ) ]
149+ fn into_async_iter ( self ) -> Self :: IntoAsyncIter ;
150+ }
151+
152+ #[ unstable( feature = "async_iterator" , issue = "79024" ) ]
153+ impl < I : AsyncIterator > IntoAsyncIterator for I {
154+ type Item = I :: Item ;
155+ type IntoAsyncIter = I ;
156+
157+ fn into_async_iter ( self ) -> Self :: IntoAsyncIter {
158+ self
159+ }
160+ }
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) ]
@@ -125,6 +128,7 @@ mod any;
125128mod array;
126129mod ascii;
127130mod asserting;
131+ mod async_iter;
128132mod atomic;
129133mod bool;
130134mod cell;
You can’t perform that action at this time.
0 commit comments