@@ -104,41 +104,6 @@ pub enum Action {
104
104
Complete ,
105
105
}
106
106
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
-
142
107
#[ derive( PartialEq ) ]
143
108
pub struct Marker < T > ( PhantomData < T > ) ;
144
109
@@ -153,9 +118,17 @@ pub enum YieldType<I, A> {
153
118
Accessor ( Marker < A > ) ,
154
119
}
155
120
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
+ }
159
132
160
133
impl BoxedResolver {
161
134
fn new < T > ( generator : T ) -> ( Result < ast:: Crate > , Self )
@@ -166,8 +139,15 @@ impl BoxedResolver {
166
139
Return = ResolverOutputs ,
167
140
> + ' static ,
168
141
{
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 } )
171
151
}
172
152
173
153
pub fn access < F : FnOnce ( & mut Resolver < ' _ > ) -> R , R > ( & mut self , f : F ) -> R {
@@ -183,15 +163,22 @@ impl BoxedResolver {
183
163
184
164
// Get the generator to call our closure
185
165
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
+ }
187
172
}
188
173
189
174
// Unwrap the result
190
175
r. unwrap ( )
191
176
}
192
177
193
178
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 ! ( ) }
195
182
}
196
183
197
184
fn initial_yield (
0 commit comments