1
+ use crate :: fmt;
1
2
use crate :: ops:: { Generator , GeneratorState } ;
2
3
use crate :: pin:: Pin ;
3
4
@@ -23,14 +24,21 @@ use crate::pin::Pin;
23
24
/// ```
24
25
#[ inline]
25
26
#[ unstable( feature = "iter_from_generator" , issue = "43122" , reason = "generators are unstable" ) ]
26
- pub fn from_generator < G : Generator < Return = ( ) > + Unpin > (
27
- generator : G ,
28
- ) -> impl Iterator < Item = G :: Yield > {
27
+ pub fn from_generator < G : Generator < Return = ( ) > + Unpin > ( generator : G ) -> FromGenerator < G > {
29
28
FromGenerator ( generator)
30
29
}
31
30
32
- struct FromGenerator < G > ( G ) ;
31
+ /// An iterator over the values yielded by an underlying generator.
32
+ ///
33
+ /// This `struct` is created by the [`iter::from_generator()`] function. See its documentation for
34
+ /// more.
35
+ ///
36
+ /// [`iter::from_generator()`]: from_generator
37
+ #[ unstable( feature = "iter_from_generator" , issue = "43122" , reason = "generators are unstable" ) ]
38
+ #[ derive( Clone ) ]
39
+ pub struct FromGenerator < G > ( G ) ;
33
40
41
+ #[ unstable( feature = "iter_from_generator" , issue = "43122" , reason = "generators are unstable" ) ]
34
42
impl < G : Generator < Return = ( ) > + Unpin > Iterator for FromGenerator < G > {
35
43
type Item = G :: Yield ;
36
44
@@ -41,3 +49,10 @@ impl<G: Generator<Return = ()> + Unpin> Iterator for FromGenerator<G> {
41
49
}
42
50
}
43
51
}
52
+
53
+ #[ unstable( feature = "iter_from_generator" , issue = "43122" , reason = "generators are unstable" ) ]
54
+ impl < G > fmt:: Debug for FromGenerator < G > {
55
+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
56
+ f. debug_struct ( "FromGenerator" ) . finish ( )
57
+ }
58
+ }
0 commit comments