Clean up marker generics for systems (#7789)
# Objective While we use `#[doc(hidden)]` to try and hide marker generics from the user, these types reveal themselves in compiler errors, adding visual noise and confusion. ## Solution Replace the `AlreadyWasSystem` marker generic with `()`, to reduce visual noise in error messages. This also makes it possible to return `impl Condition<()>` from combinators. For function systems, use their function signature as the marker type. This should drastically improve the legibility of some error messages. The `InputMarker` type has been removed, since it is unnecessary.
This commit is contained in:
		
							parent
							
								
									ee4c8c5ecd
								
							
						
					
					
						commit
						695d30bd54
					
				| @ -137,7 +137,7 @@ pub mod common_conditions { | ||||
|         event::{Event, EventReader}, | ||||
|         prelude::{Component, Query, With}, | ||||
|         schedule::{State, States}, | ||||
|         system::{In, IntoPipeSystem, ReadOnlySystem, Res, Resource}, | ||||
|         system::{In, IntoPipeSystem, Res, Resource}, | ||||
|     }; | ||||
| 
 | ||||
|     /// Generates a [`Condition`](super::Condition)-satisfying closure that returns `true`
 | ||||
| @ -373,9 +373,7 @@ pub mod common_conditions { | ||||
|     /// #
 | ||||
|     /// # fn my_system() { unreachable!() }
 | ||||
|     /// ```
 | ||||
|     pub fn not<Marker>( | ||||
|         condition: impl Condition<Marker>, | ||||
|     ) -> impl ReadOnlySystem<In = (), Out = bool> { | ||||
|     pub fn not<Marker>(condition: impl Condition<Marker>) -> impl Condition<()> { | ||||
|         condition.pipe(|In(val): In<bool>| !val) | ||||
|     } | ||||
| } | ||||
|  | ||||
| @ -4,8 +4,8 @@ use crate::{ | ||||
|     component::ComponentId, | ||||
|     query::Access, | ||||
|     system::{ | ||||
|         check_system_change_tick, ExclusiveSystemParam, ExclusiveSystemParamItem, In, InputMarker, | ||||
|         IntoSystem, System, SystemMeta, | ||||
|         check_system_change_tick, ExclusiveSystemParam, ExclusiveSystemParamItem, In, IntoSystem, | ||||
|         System, SystemMeta, | ||||
|     }, | ||||
|     world::{World, WorldId}, | ||||
| }; | ||||
| @ -181,7 +181,7 @@ pub trait ExclusiveSystemParamFunction<Marker>: Send + Sync + 'static { | ||||
| macro_rules! impl_exclusive_system_function { | ||||
|     ($($param: ident),*) => { | ||||
|         #[allow(non_snake_case)] | ||||
|         impl<Out, Func: Send + Sync + 'static, $($param: ExclusiveSystemParam),*> ExclusiveSystemParamFunction<((), Out, $($param,)*)> for Func | ||||
|         impl<Out, Func: Send + Sync + 'static, $($param: ExclusiveSystemParam),*> ExclusiveSystemParamFunction<fn($($param,)*) -> Out> for Func | ||||
|         where | ||||
|         for <'a> &'a mut Func: | ||||
|                 FnMut(&mut World, $($param),*) -> Out + | ||||
| @ -209,7 +209,7 @@ macro_rules! impl_exclusive_system_function { | ||||
|             } | ||||
|         } | ||||
|         #[allow(non_snake_case)] | ||||
|         impl<Input, Out, Func: Send + Sync + 'static, $($param: ExclusiveSystemParam),*> ExclusiveSystemParamFunction<(Input, Out, $($param,)* InputMarker)> for Func | ||||
|         impl<Input, Out, Func: Send + Sync + 'static, $($param: ExclusiveSystemParam),*> ExclusiveSystemParamFunction<fn(In<Input>, $($param,)*) -> Out> for Func | ||||
|         where | ||||
|         for <'a> &'a mut Func: | ||||
|                 FnMut(In<Input>, &mut World, $($param),*) -> Out + | ||||
|  | ||||
| @ -325,10 +325,8 @@ pub trait IntoSystem<In, Out, Marker>: Sized { | ||||
|     fn into_system(this: Self) -> Self::System; | ||||
| } | ||||
| 
 | ||||
| pub struct AlreadyWasSystem; | ||||
| 
 | ||||
| // Systems implicitly implement IntoSystem
 | ||||
| impl<In, Out, Sys: System<In = In, Out = Out>> IntoSystem<In, Out, AlreadyWasSystem> for Sys { | ||||
| impl<In, Out, Sys: System<In = In, Out = Out>> IntoSystem<In, Out, ()> for Sys { | ||||
|     type System = Sys; | ||||
|     fn into_system(this: Self) -> Sys { | ||||
|         this | ||||
| @ -362,8 +360,6 @@ impl<In, Out, Sys: System<In = In, Out = Out>> IntoSystem<In, Out, AlreadyWasSys | ||||
| /// }
 | ||||
| /// ```
 | ||||
| pub struct In<In>(pub In); | ||||
| #[doc(hidden)] | ||||
| pub struct InputMarker; | ||||
| 
 | ||||
| /// The [`System`] counter part of an ordinary function.
 | ||||
| ///
 | ||||
| @ -611,7 +607,7 @@ pub trait SystemParamFunction<Marker>: Send + Sync + 'static { | ||||
| macro_rules! impl_system_function { | ||||
|     ($($param: ident),*) => { | ||||
|         #[allow(non_snake_case)] | ||||
|         impl<Out, Func: Send + Sync + 'static, $($param: SystemParam),*> SystemParamFunction<((), Out, $($param,)*)> for Func | ||||
|         impl<Out, Func: Send + Sync + 'static, $($param: SystemParam),*> SystemParamFunction<fn($($param,)*) -> Out> for Func | ||||
|         where | ||||
|         for <'a> &'a mut Func: | ||||
|                 FnMut($($param),*) -> Out + | ||||
| @ -638,7 +634,7 @@ macro_rules! impl_system_function { | ||||
|         } | ||||
| 
 | ||||
|         #[allow(non_snake_case)] | ||||
|         impl<Input, Out, Func: Send + Sync + 'static, $($param: SystemParam),*> SystemParamFunction<(Input, Out, $($param,)* InputMarker)> for Func | ||||
|         impl<Input, Out, Func: Send + Sync + 'static, $($param: SystemParam),*> SystemParamFunction<fn(In<Input>, $($param,)*) -> Out> for Func | ||||
|         where | ||||
|         for <'a> &'a mut Func: | ||||
|                 FnMut(In<Input>, $($param),*) -> Out + | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user
	 JoJoJet
						JoJoJet