File tree 2 files changed +40
-0
lines changed
2 files changed +40
-0
lines changed Original file line number Diff line number Diff line change
1
+ use crate :: pin:: Pin ;
2
+
3
+ use crate :: stream:: Stream ;
4
+ use crate :: task:: { Context , Poll } ;
5
+
6
+ /// A stream that was created from iterator.
7
+ ///
8
+ /// This stream is created by the [`from_iter`] function.
9
+ /// See it documentation for more.
10
+ ///
11
+ /// [`from_iter`]: fn.from_iter.html
12
+ #[ unstable( feature = "stream_from_iter" , issue = "81798" ) ]
13
+ #[ derive( Clone , Debug ) ]
14
+ pub struct FromIter < I > {
15
+ iter : I ,
16
+ }
17
+
18
+ #[ unstable( feature = "stream_from_iter" , issue = "81798" ) ]
19
+ impl < I > Unpin for FromIter < I > { }
20
+
21
+ /// Converts an iterator into a stream.
22
+ #[ unstable( feature = "stream_from_iter" , issue = "81798" ) ]
23
+ pub fn from_iter < I : IntoIterator > ( iter : I ) -> FromIter < I :: IntoIter > {
24
+ FromIter { iter : iter. into_iter ( ) }
25
+ }
26
+
27
+ #[ unstable( feature = "stream_from_iter" , issue = "81798" ) ]
28
+ impl < I : Iterator > Stream for FromIter < I > {
29
+ type Item = I :: Item ;
30
+
31
+ fn poll_next ( mut self : Pin < & mut Self > , _cx : & mut Context < ' _ > ) -> Poll < Option < Self :: Item > > {
32
+ Poll :: Ready ( self . iter . next ( ) )
33
+ }
34
+
35
+ fn size_hint ( & self ) -> ( usize , Option < usize > ) {
36
+ self . iter . size_hint ( )
37
+ }
38
+ }
Original file line number Diff line number Diff line change 122
122
//! warning: unused result that must be used: streams do nothing unless polled
123
123
//! ```
124
124
125
+ mod from_iter;
125
126
mod stream;
126
127
128
+ pub use from_iter:: { from_iter, FromIter } ;
127
129
pub use stream:: Stream ;
You can’t perform that action at this time.
0 commit comments