Remind users to initialize their systems before running them (#3947)
# Objective - Manually running systems is a somewhat obscure process: systems must be initialized before they are run - The unwrap is rather hard to debug. ## Solution - Replace unwraps in `FunctionSystem` methods with expects (progress towards #3892). - Briefly document this requirement.
This commit is contained in:
		
							parent
							
								
									61a3494a06
								
							
						
					
					
						commit
						8283db69b4
					
				| @ -305,6 +305,8 @@ pub struct InputMarker; | |||||||
| /// You get this by calling [`IntoSystem::into_system`]  on a function that only accepts
 | /// You get this by calling [`IntoSystem::into_system`]  on a function that only accepts
 | ||||||
| /// [`SystemParam`]s. The output of the system becomes the functions return type, while the input
 | /// [`SystemParam`]s. The output of the system becomes the functions return type, while the input
 | ||||||
| /// becomes the functions [`In`] tagged parameter or `()` if no such parameter exists.
 | /// becomes the functions [`In`] tagged parameter or `()` if no such parameter exists.
 | ||||||
|  | ///
 | ||||||
|  | /// [`FunctionSystem`] must be `.initialized` before they can be run.
 | ||||||
| pub struct FunctionSystem<In, Out, Param, Marker, F> | pub struct FunctionSystem<In, Out, Param, Marker, F> | ||||||
| where | where | ||||||
|     Param: SystemParam, |     Param: SystemParam, | ||||||
| @ -378,7 +380,7 @@ where | |||||||
|         let change_tick = world.increment_change_tick(); |         let change_tick = world.increment_change_tick(); | ||||||
|         let out = self.func.run( |         let out = self.func.run( | ||||||
|             input, |             input, | ||||||
|             self.param_state.as_mut().unwrap(), |             self.param_state.as_mut().expect("System's param_state was not found. Did you forget to initialize this system before running it?"), | ||||||
|             &self.system_meta, |             &self.system_meta, | ||||||
|             world, |             world, | ||||||
|             change_tick, |             change_tick, | ||||||
| @ -389,7 +391,7 @@ where | |||||||
| 
 | 
 | ||||||
|     #[inline] |     #[inline] | ||||||
|     fn apply_buffers(&mut self, world: &mut World) { |     fn apply_buffers(&mut self, world: &mut World) { | ||||||
|         let param_state = self.param_state.as_mut().unwrap(); |         let param_state = self.param_state.as_mut().expect("System's param_state was not found. Did you forget to initialize this system before running it?"); | ||||||
|         param_state.apply(world); |         param_state.apply(world); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user
	 Alice Cecile
						Alice Cecile