1+ use crate :: fmt;
12use crate :: ops:: { Generator , GeneratorState } ;
23use crate :: pin:: Pin ;
34
@@ -23,14 +24,21 @@ use crate::pin::Pin;
2324/// ```
2425#[ inline]
2526#[ 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 > {
2928 FromGenerator ( generator)
3029}
3130
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 ) ;
3340
41+ #[ unstable( feature = "iter_from_generator" , issue = "43122" , reason = "generators are unstable" ) ]
3442impl < G : Generator < Return = ( ) > + Unpin > Iterator for FromGenerator < G > {
3543 type Item = G :: Yield ;
3644
@@ -41,3 +49,10 @@ impl<G: Generator<Return = ()> + Unpin> Iterator for FromGenerator<G> {
4149 }
4250 }
4351}
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