@@ -104,41 +104,6 @@ pub enum Action {
104104 Complete ,
105105}
106106
107- pub struct PinnedGenerator < I , A , R > {
108- generator : Pin < Box < dyn Generator < Action , Yield = YieldType < I , A > , Return = R > > > ,
109- }
110-
111- impl < I , A , R > PinnedGenerator < I , A , R > {
112- pub fn new < T : Generator < Action , Yield = YieldType < I , A > , Return = R > + ' static > (
113- generator : T ,
114- ) -> ( I , Self ) {
115- let mut result = PinnedGenerator { generator : Box :: pin ( generator) } ;
116-
117- // Run it to the first yield to set it up
118- let init = match Pin :: new ( & mut result. generator ) . resume ( Action :: Initial ) {
119- GeneratorState :: Yielded ( YieldType :: Initial ( y) ) => y,
120- _ => panic ! ( ) ,
121- } ;
122-
123- ( init, result)
124- }
125-
126- pub unsafe fn access ( & mut self , closure : * mut dyn FnMut ( ) ) {
127- // Call the generator, which in turn will call the closure
128- if let GeneratorState :: Complete ( _) =
129- Pin :: new ( & mut self . generator ) . resume ( Action :: Access ( AccessAction ( closure) ) )
130- {
131- panic ! ( )
132- }
133- }
134-
135- pub fn complete ( & mut self ) -> R {
136- // Tell the generator we want it to complete, consuming it and yielding a result
137- let result = Pin :: new ( & mut self . generator ) . resume ( Action :: Complete ) ;
138- if let GeneratorState :: Complete ( r) = result { r } else { panic ! ( ) }
139- }
140- }
141-
142107#[ derive( PartialEq ) ]
143108pub struct Marker < T > ( PhantomData < T > ) ;
144109
@@ -153,9 +118,17 @@ pub enum YieldType<I, A> {
153118 Accessor ( Marker < A > ) ,
154119}
155120
156- pub struct BoxedResolver (
157- PinnedGenerator < Result < ast:: Crate > , fn ( & mut Resolver < ' _ > ) , ResolverOutputs > ,
158- ) ;
121+ pub struct BoxedResolver {
122+ generator : Pin <
123+ Box <
124+ dyn Generator <
125+ Action ,
126+ Yield = YieldType < Result < ast:: Crate > , fn ( & mut Resolver < ' _ > ) > ,
127+ Return = ResolverOutputs ,
128+ > ,
129+ > ,
130+ > ,
131+ }
159132
160133impl BoxedResolver {
161134 fn new < T > ( generator : T ) -> ( Result < ast:: Crate > , Self )
@@ -166,8 +139,15 @@ impl BoxedResolver {
166139 Return = ResolverOutputs ,
167140 > + ' static ,
168141 {
169- let ( initial, pinned) = PinnedGenerator :: new ( generator) ;
170- ( initial, BoxedResolver ( pinned) )
142+ let mut generator = Box :: pin ( generator) ;
143+
144+ // Run it to the first yield to set it up
145+ let init = match Pin :: new ( & mut generator) . resume ( Action :: Initial ) {
146+ GeneratorState :: Yielded ( YieldType :: Initial ( y) ) => y,
147+ _ => panic ! ( ) ,
148+ } ;
149+
150+ ( init, BoxedResolver { generator } )
171151 }
172152
173153 pub fn access < F : FnOnce ( & mut Resolver < ' _ > ) -> R , R > ( & mut self , f : F ) -> R {
@@ -183,15 +163,22 @@ impl BoxedResolver {
183163
184164 // Get the generator to call our closure
185165 unsafe {
186- self . 0 . access ( :: std:: mem:: transmute ( mut_f) ) ;
166+ // Call the generator, which in turn will call the closure
167+ if let GeneratorState :: Complete ( _) = Pin :: new ( & mut self . generator )
168+ . resume ( Action :: Access ( AccessAction ( :: std:: mem:: transmute ( mut_f) ) ) )
169+ {
170+ panic ! ( )
171+ }
187172 }
188173
189174 // Unwrap the result
190175 r. unwrap ( )
191176 }
192177
193178 pub fn complete ( mut self ) -> ResolverOutputs {
194- self . 0 . complete ( )
179+ // Tell the generator we want it to complete, consuming it and yielding a result
180+ let result = Pin :: new ( & mut self . generator ) . resume ( Action :: Complete ) ;
181+ if let GeneratorState :: Complete ( r) = result { r } else { panic ! ( ) }
195182 }
196183
197184 fn initial_yield (
0 commit comments