@@ -3,7 +3,7 @@ use crate::{
33        RunCriteriaDescriptor ,  RunCriteriaDescriptorCoercion ,  RunCriteriaLabel ,  ShouldRun , 
44        SystemSet , 
55    } , 
6-     system:: { ConfigurableSystem ,   In ,  IntoChainSystem ,  Local ,  Res ,  ResMut } , 
6+     system:: { In ,  IntoChainSystem ,  Local ,  Res ,  ResMut } , 
77} ; 
88use  std:: { any:: TypeId ,  fmt:: Debug ,  hash:: Hash } ; 
99use  thiserror:: Error ; 
@@ -98,134 +98,128 @@ impl<T> State<T>
9898where 
9999    T :  StateData , 
100100{ 
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 ( ) 
104105        } ) 
105-         . config ( |( _,  pred) | * pred = Some ( Some ( s. clone ( ) ) ) ) 
106106        . chain ( should_run_adapter :: < T > ) 
107107        . 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 ) ) 
109109    } 
110110
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  { 
115114            Some ( StateTransition :: Pausing ( ref  relevant,  _) ) 
116115            | Some ( StateTransition :: Resuming ( _,  ref  relevant) )  => { 
117-                 if  relevant == pred. as_ref ( ) . unwrap ( )  { 
116+                 if  relevant == & pred { 
118117                    * is_inactive = !* is_inactive; 
119118                } 
120119                false 
121120            } 
122121            Some ( _)  => false , 
123122            None  => * is_inactive, 
124123        } ) 
125-         . config ( |( _,  _,  pred) | * pred = Some ( Some ( s. clone ( ) ) ) ) 
126124        . chain ( should_run_adapter :: < T > ) 
127125        . 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 ) ) 
129127    } 
130128
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  { 
135132            Some ( StateTransition :: Entering ( ref  relevant,  _) ) 
136133            | Some ( StateTransition :: ExitingToResume ( _,  ref  relevant) )  => { 
137-                 if  relevant == pred. as_ref ( ) . unwrap ( )  { 
134+                 if  relevant == & pred { 
138135                    * is_in_stack = !* is_in_stack; 
139136                } 
140137                false 
141138            } 
142139            Some ( StateTransition :: ExitingFull ( _,  ref  relevant) )  => { 
143-                 if  relevant == pred. as_ref ( ) . unwrap ( )  { 
140+                 if  relevant == & pred { 
144141                    * is_in_stack = !* is_in_stack; 
145142                } 
146143                false 
147144            } 
148145            Some ( StateTransition :: Startup )  => { 
149-                 if  state. stack . last ( ) . unwrap ( )  == pred. as_ref ( ) . unwrap ( )  { 
146+                 if  state. stack . last ( ) . unwrap ( )  == & pred { 
150147                    * is_in_stack = !* is_in_stack; 
151148                } 
152149                false 
153150            } 
154151            Some ( _)  => false , 
155152            None  => * is_in_stack, 
156153        } ) 
157-         . config ( |( _,  _,  pred) | * pred = Some ( Some ( s. clone ( ) ) ) ) 
158154        . chain ( should_run_adapter :: < T > ) 
159155        . 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 ) ) 
161157    } 
162158
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 > > | { 
165162            state
166163                . transition 
167164                . as_ref ( ) 
168165                . 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, 
173168                    _ => false , 
174169                } ) 
175170        } ) 
176-         . config ( |( _,  pred) | * pred = Some ( Some ( s. clone ( ) ) ) ) 
177171        . chain ( should_run_adapter :: < T > ) 
178172        . 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 ) ) 
180174    } 
181175
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 > > | { 
184179            state
185180                . transition 
186181                . as_ref ( ) 
187182                . map_or ( false ,  |transition| match  transition { 
188183                    StateTransition :: ExitingToResume ( exiting,  _) 
189-                     | StateTransition :: ExitingFull ( exiting,  _)  => exiting == pred. as_ref ( ) . unwrap ( ) , 
184+                     | StateTransition :: ExitingFull ( exiting,  _)  => exiting == & pred, 
190185                    _ => false , 
191186                } ) 
192187        } ) 
193-         . config ( |( _,  pred) | * pred = Some ( Some ( s. clone ( ) ) ) ) 
194188        . chain ( should_run_adapter :: < T > ) 
195189        . 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 ) ) 
197191    } 
198192
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 > > | { 
201196            state
202197                . transition 
203198                . as_ref ( ) 
204199                . map_or ( false ,  |transition| match  transition { 
205-                     StateTransition :: Pausing ( pausing,  _)  => pausing == pred. as_ref ( ) . unwrap ( ) , 
200+                     StateTransition :: Pausing ( pausing,  _)  => pausing == & pred, 
206201                    _ => false , 
207202                } ) 
208203        } ) 
209-         . config ( |( _,  pred) | * pred = Some ( Some ( s. clone ( ) ) ) ) 
210204        . chain ( should_run_adapter :: < T > ) 
211205        . 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 ) ) 
213207    } 
214208
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 > > | { 
217212            state
218213                . transition 
219214                . as_ref ( ) 
220215                . map_or ( false ,  |transition| match  transition { 
221-                     StateTransition :: Resuming ( _,  resuming)  => resuming == pred. as_ref ( ) . unwrap ( ) , 
216+                     StateTransition :: Resuming ( _,  resuming)  => resuming == & pred, 
222217                    _ => false , 
223218                } ) 
224219        } ) 
225-         . config ( |( _,  pred) | * pred = Some ( Some ( s. clone ( ) ) ) ) 
226220        . chain ( should_run_adapter :: < T > ) 
227221        . 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 ) ) 
229223    } 
230224
231225    pub  fn  on_update_set ( s :  T )  -> SystemSet  { 
0 commit comments