@@ -3,7 +3,7 @@ use crate::{
3
3
RunCriteriaDescriptor , RunCriteriaDescriptorCoercion , RunCriteriaLabel , ShouldRun ,
4
4
SystemSet ,
5
5
} ,
6
- system:: { ConfigurableSystem , In , IntoChainSystem , Local , Res , ResMut } ,
6
+ system:: { In , IntoChainSystem , Local , Res , ResMut } ,
7
7
} ;
8
8
use std:: { any:: TypeId , fmt:: Debug , hash:: Hash } ;
9
9
use thiserror:: Error ;
@@ -98,134 +98,128 @@ impl<T> State<T>
98
98
where
99
99
T : StateData ,
100
100
{
101
- pub fn on_update ( s : T ) -> RunCriteriaDescriptor {
102
- ( |state : Res < State < T > > , pred : Local < Option < T > > | {
103
- state. stack . last ( ) . unwrap ( ) == pred. as_ref ( ) . unwrap ( ) && state. transition . is_none ( )
101
+ pub fn on_update ( pred : T ) -> RunCriteriaDescriptor {
102
+ let pred_clone = pred. clone ( ) ;
103
+ ( move |state : Res < State < T > > | {
104
+ state. stack . last ( ) . unwrap ( ) == & pred && state. transition . is_none ( )
104
105
} )
105
- . config ( |( _, pred) | * pred = Some ( Some ( s. clone ( ) ) ) )
106
106
. chain ( should_run_adapter :: < T > )
107
107
. after ( DriverLabel :: of :: < T > ( ) )
108
- . label_discard_if_duplicate ( StateCallback :: Update . into_label ( s ) )
108
+ . label_discard_if_duplicate ( StateCallback :: Update . into_label ( pred_clone ) )
109
109
}
110
110
111
- pub fn on_inactive_update ( s : T ) -> RunCriteriaDescriptor {
112
- ( |state : Res < State < T > > , mut is_inactive : Local < bool > , pred : Local < Option < T > > | match & state
113
- . transition
114
- {
111
+ pub fn on_inactive_update ( pred : T ) -> RunCriteriaDescriptor {
112
+ let pred_clone = pred. clone ( ) ;
113
+ ( move |state : Res < State < T > > , mut is_inactive : Local < bool > | match & state. transition {
115
114
Some ( StateTransition :: Pausing ( ref relevant, _) )
116
115
| Some ( StateTransition :: Resuming ( _, ref relevant) ) => {
117
- if relevant == pred. as_ref ( ) . unwrap ( ) {
116
+ if relevant == & pred {
118
117
* is_inactive = !* is_inactive;
119
118
}
120
119
false
121
120
}
122
121
Some ( _) => false ,
123
122
None => * is_inactive,
124
123
} )
125
- . config ( |( _, _, pred) | * pred = Some ( Some ( s. clone ( ) ) ) )
126
124
. chain ( should_run_adapter :: < T > )
127
125
. after ( DriverLabel :: of :: < T > ( ) )
128
- . label_discard_if_duplicate ( StateCallback :: InactiveUpdate . into_label ( s ) )
126
+ . label_discard_if_duplicate ( StateCallback :: InactiveUpdate . into_label ( pred_clone ) )
129
127
}
130
128
131
- pub fn on_in_stack_update ( s : T ) -> RunCriteriaDescriptor {
132
- ( |state : Res < State < T > > , mut is_in_stack : Local < bool > , pred : Local < Option < T > > | match & state
133
- . transition
134
- {
129
+ pub fn on_in_stack_update ( pred : T ) -> RunCriteriaDescriptor {
130
+ let pred_clone = pred. clone ( ) ;
131
+ ( move |state : Res < State < T > > , mut is_in_stack : Local < bool > | match & state. transition {
135
132
Some ( StateTransition :: Entering ( ref relevant, _) )
136
133
| Some ( StateTransition :: ExitingToResume ( _, ref relevant) ) => {
137
- if relevant == pred. as_ref ( ) . unwrap ( ) {
134
+ if relevant == & pred {
138
135
* is_in_stack = !* is_in_stack;
139
136
}
140
137
false
141
138
}
142
139
Some ( StateTransition :: ExitingFull ( _, ref relevant) ) => {
143
- if relevant == pred. as_ref ( ) . unwrap ( ) {
140
+ if relevant == & pred {
144
141
* is_in_stack = !* is_in_stack;
145
142
}
146
143
false
147
144
}
148
145
Some ( StateTransition :: Startup ) => {
149
- if state. stack . last ( ) . unwrap ( ) == pred. as_ref ( ) . unwrap ( ) {
146
+ if state. stack . last ( ) . unwrap ( ) == & pred {
150
147
* is_in_stack = !* is_in_stack;
151
148
}
152
149
false
153
150
}
154
151
Some ( _) => false ,
155
152
None => * is_in_stack,
156
153
} )
157
- . config ( |( _, _, pred) | * pred = Some ( Some ( s. clone ( ) ) ) )
158
154
. chain ( should_run_adapter :: < T > )
159
155
. after ( DriverLabel :: of :: < T > ( ) )
160
- . label_discard_if_duplicate ( StateCallback :: InStackUpdate . into_label ( s ) )
156
+ . label_discard_if_duplicate ( StateCallback :: InStackUpdate . into_label ( pred_clone ) )
161
157
}
162
158
163
- pub fn on_enter ( s : T ) -> RunCriteriaDescriptor {
164
- ( |state : Res < State < T > > , pred : Local < Option < T > > | {
159
+ pub fn on_enter ( pred : T ) -> RunCriteriaDescriptor {
160
+ let pred_clone = pred. clone ( ) ;
161
+ ( move |state : Res < State < T > > | {
165
162
state
166
163
. transition
167
164
. as_ref ( )
168
165
. map_or ( false , |transition| match transition {
169
- StateTransition :: Entering ( _, entering) => entering == pred. as_ref ( ) . unwrap ( ) ,
170
- StateTransition :: Startup => {
171
- state. stack . last ( ) . unwrap ( ) == pred. as_ref ( ) . unwrap ( )
172
- }
166
+ StateTransition :: Entering ( _, entering) => entering == & pred,
167
+ StateTransition :: Startup => state. stack . last ( ) . unwrap ( ) == & pred,
173
168
_ => false ,
174
169
} )
175
170
} )
176
- . config ( |( _, pred) | * pred = Some ( Some ( s. clone ( ) ) ) )
177
171
. chain ( should_run_adapter :: < T > )
178
172
. after ( DriverLabel :: of :: < T > ( ) )
179
- . label_discard_if_duplicate ( StateCallback :: Enter . into_label ( s ) )
173
+ . label_discard_if_duplicate ( StateCallback :: Enter . into_label ( pred_clone ) )
180
174
}
181
175
182
- pub fn on_exit ( s : T ) -> RunCriteriaDescriptor {
183
- ( |state : Res < State < T > > , pred : Local < Option < T > > | {
176
+ pub fn on_exit ( pred : T ) -> RunCriteriaDescriptor {
177
+ let pred_clone = pred. clone ( ) ;
178
+ ( move |state : Res < State < T > > | {
184
179
state
185
180
. transition
186
181
. as_ref ( )
187
182
. map_or ( false , |transition| match transition {
188
183
StateTransition :: ExitingToResume ( exiting, _)
189
- | StateTransition :: ExitingFull ( exiting, _) => exiting == pred. as_ref ( ) . unwrap ( ) ,
184
+ | StateTransition :: ExitingFull ( exiting, _) => exiting == & pred,
190
185
_ => false ,
191
186
} )
192
187
} )
193
- . config ( |( _, pred) | * pred = Some ( Some ( s. clone ( ) ) ) )
194
188
. chain ( should_run_adapter :: < T > )
195
189
. after ( DriverLabel :: of :: < T > ( ) )
196
- . label_discard_if_duplicate ( StateCallback :: Exit . into_label ( s ) )
190
+ . label_discard_if_duplicate ( StateCallback :: Exit . into_label ( pred_clone ) )
197
191
}
198
192
199
- pub fn on_pause ( s : T ) -> RunCriteriaDescriptor {
200
- ( |state : Res < State < T > > , pred : Local < Option < T > > | {
193
+ pub fn on_pause ( pred : T ) -> RunCriteriaDescriptor {
194
+ let pred_clone = pred. clone ( ) ;
195
+ ( move |state : Res < State < T > > | {
201
196
state
202
197
. transition
203
198
. as_ref ( )
204
199
. map_or ( false , |transition| match transition {
205
- StateTransition :: Pausing ( pausing, _) => pausing == pred. as_ref ( ) . unwrap ( ) ,
200
+ StateTransition :: Pausing ( pausing, _) => pausing == & pred,
206
201
_ => false ,
207
202
} )
208
203
} )
209
- . config ( |( _, pred) | * pred = Some ( Some ( s. clone ( ) ) ) )
210
204
. chain ( should_run_adapter :: < T > )
211
205
. after ( DriverLabel :: of :: < T > ( ) )
212
- . label_discard_if_duplicate ( StateCallback :: Pause . into_label ( s ) )
206
+ . label_discard_if_duplicate ( StateCallback :: Pause . into_label ( pred_clone ) )
213
207
}
214
208
215
- pub fn on_resume ( s : T ) -> RunCriteriaDescriptor {
216
- ( |state : Res < State < T > > , pred : Local < Option < T > > | {
209
+ pub fn on_resume ( pred : T ) -> RunCriteriaDescriptor {
210
+ let pred_clone = pred. clone ( ) ;
211
+ ( move |state : Res < State < T > > | {
217
212
state
218
213
. transition
219
214
. as_ref ( )
220
215
. map_or ( false , |transition| match transition {
221
- StateTransition :: Resuming ( _, resuming) => resuming == pred. as_ref ( ) . unwrap ( ) ,
216
+ StateTransition :: Resuming ( _, resuming) => resuming == & pred,
222
217
_ => false ,
223
218
} )
224
219
} )
225
- . config ( |( _, pred) | * pred = Some ( Some ( s. clone ( ) ) ) )
226
220
. chain ( should_run_adapter :: < T > )
227
221
. after ( DriverLabel :: of :: < T > ( ) )
228
- . label_discard_if_duplicate ( StateCallback :: Resume . into_label ( s ) )
222
+ . label_discard_if_duplicate ( StateCallback :: Resume . into_label ( pred_clone ) )
229
223
}
230
224
231
225
pub fn on_update_set ( s : T ) -> SystemSet {
0 commit comments