@@ -25,6 +25,7 @@ pub struct PinnedGenerator<I, A, R> {
25
25
}
26
26
27
27
impl < I , A , R > PinnedGenerator < I , A , R > {
28
+ #[ cfg( bootstrap) ]
28
29
pub fn new < T : Generator < Yield = YieldType < I , A > , Return = R > + ' static > (
29
30
generator : T ,
30
31
) -> ( I , Self ) {
@@ -39,6 +40,22 @@ impl<I, A, R> PinnedGenerator<I, A, R> {
39
40
( init, result)
40
41
}
41
42
43
+ #[ cfg( not( bootstrap) ) ]
44
+ pub fn new < T : Generator < Yield = YieldType < I , A > , Return = R > + ' static > (
45
+ generator : T ,
46
+ ) -> ( I , Self ) {
47
+ let mut result = PinnedGenerator { generator : Box :: pin ( generator) } ;
48
+
49
+ // Run it to the first yield to set it up
50
+ let init = match Pin :: new ( & mut result. generator ) . resume ( ( ) ) {
51
+ GeneratorState :: Yielded ( YieldType :: Initial ( y) ) => y,
52
+ _ => panic ! ( ) ,
53
+ } ;
54
+
55
+ ( init, result)
56
+ }
57
+
58
+ #[ cfg( bootstrap) ]
42
59
pub unsafe fn access ( & mut self , closure : * mut dyn FnMut ( ) ) {
43
60
BOX_REGION_ARG . with ( |i| {
44
61
i. set ( Action :: Access ( AccessAction ( closure) ) ) ;
@@ -50,13 +67,35 @@ impl<I, A, R> PinnedGenerator<I, A, R> {
50
67
}
51
68
}
52
69
70
+ #[ cfg( not( bootstrap) ) ]
71
+ pub unsafe fn access ( & mut self , closure : * mut dyn FnMut ( ) ) {
72
+ BOX_REGION_ARG . with ( |i| {
73
+ i. set ( Action :: Access ( AccessAction ( closure) ) ) ;
74
+ } ) ;
75
+
76
+ // Call the generator, which in turn will call the closure in BOX_REGION_ARG
77
+ if let GeneratorState :: Complete ( _) = Pin :: new ( & mut self . generator ) . resume ( ( ) ) {
78
+ panic ! ( )
79
+ }
80
+ }
81
+
82
+ #[ cfg( bootstrap) ]
53
83
pub fn complete ( & mut self ) -> R {
54
84
// Tell the generator we want it to complete, consuming it and yielding a result
55
85
BOX_REGION_ARG . with ( |i| i. set ( Action :: Complete ) ) ;
56
86
57
87
let result = Pin :: new ( & mut self . generator ) . resume ( ) ;
58
88
if let GeneratorState :: Complete ( r) = result { r } else { panic ! ( ) }
59
89
}
90
+
91
+ #[ cfg( not( bootstrap) ) ]
92
+ pub fn complete ( & mut self ) -> R {
93
+ // Tell the generator we want it to complete, consuming it and yielding a result
94
+ BOX_REGION_ARG . with ( |i| i. set ( Action :: Complete ) ) ;
95
+
96
+ let result = Pin :: new ( & mut self . generator ) . resume ( ( ) ) ;
97
+ if let GeneratorState :: Complete ( r) = result { r } else { panic ! ( ) }
98
+ }
60
99
}
61
100
62
101
#[ derive( PartialEq ) ]
0 commit comments