From 7cd2ee2bbd6003f45b4873b66a3022d5764e510d Mon Sep 17 00:00:00 2001 From: JoJoJet <21144246+JoJoJet@users.noreply.github.com> Date: Thu, 2 Mar 2023 17:19:47 +0000 Subject: [PATCH] Use default-implemented methods for `IntoSystemConfig<>` (#7870) # Objective The trait `IntoSystemConfig<>` requires each implementer to repeat every single member method, even though they can all be implemented by just deferring to `SystemConfig`. ## Solution Add default implementations to most member methods. --- crates/bevy_ecs/src/schedule/config.rs | 207 +++++++------------------ 1 file changed, 53 insertions(+), 154 deletions(-) diff --git a/crates/bevy_ecs/src/schedule/config.rs b/crates/bevy_ecs/src/schedule/config.rs index 899985fb22..54eb9f863f 100644 --- a/crates/bevy_ecs/src/schedule/config.rs +++ b/crates/bevy_ecs/src/schedule/config.rs @@ -82,113 +82,61 @@ fn ambiguous_with(graph_info: &mut GraphInfo, set: BoxedSystemSet) { /// Types that can be converted into a [`SystemSetConfig`]. /// /// This has been implemented for all types that implement [`SystemSet`] and boxed trait objects. -pub trait IntoSystemSetConfig { +pub trait IntoSystemSetConfig: Sized { /// Convert into a [`SystemSetConfig`]. #[doc(hidden)] fn into_config(self) -> SystemSetConfig; /// Add to the provided `set`. #[track_caller] - fn in_set(self, set: impl FreeSystemSet) -> SystemSetConfig; + fn in_set(self, set: impl FreeSystemSet) -> SystemSetConfig { + self.into_config().in_set(set) + } /// Add to the provided "base" `set`. For more information on base sets, see [`SystemSet::is_base`]. #[track_caller] - fn in_base_set(self, set: impl BaseSystemSet) -> SystemSetConfig; + fn in_base_set(self, set: impl BaseSystemSet) -> SystemSetConfig { + self.into_config().in_base_set(set) + } /// Add this set to the schedules's default base set. - fn in_default_base_set(self) -> SystemSetConfig; + fn in_default_base_set(self) -> SystemSetConfig { + self.into_config().in_default_base_set() + } /// Run before all systems in `set`. - fn before(self, set: impl IntoSystemSet) -> SystemSetConfig; + fn before(self, set: impl IntoSystemSet) -> SystemSetConfig { + self.into_config().before(set) + } /// Run after all systems in `set`. - fn after(self, set: impl IntoSystemSet) -> SystemSetConfig; + fn after(self, set: impl IntoSystemSet) -> SystemSetConfig { + self.into_config().after(set) + } /// Run the systems in this set only if the [`Condition`] is `true`. /// /// The `Condition` will be evaluated at most once (per schedule run), /// the first time a system in this set prepares to run. - fn run_if(self, condition: impl Condition) -> SystemSetConfig; + fn run_if(self, condition: impl Condition) -> SystemSetConfig { + self.into_config().run_if(condition) + } /// Suppress warnings and errors that would result from systems in this set having ambiguities /// (conflicting access but indeterminate order) with systems in `set`. - fn ambiguous_with(self, set: impl IntoSystemSet) -> SystemSetConfig; + fn ambiguous_with(self, set: impl IntoSystemSet) -> SystemSetConfig { + self.into_config().ambiguous_with(set) + } /// Suppress warnings and errors that would result from systems in this set having ambiguities /// (conflicting access but indeterminate order) with any other system. - fn ambiguous_with_all(self) -> SystemSetConfig; + fn ambiguous_with_all(self) -> SystemSetConfig { + self.into_config().ambiguous_with_all() + } } impl IntoSystemSetConfig for S { fn into_config(self) -> SystemSetConfig { SystemSetConfig::new(Box::new(self)) } - - #[track_caller] - fn in_set(self, set: impl FreeSystemSet) -> SystemSetConfig { - self.into_config().in_set(set) - } - - #[track_caller] - fn in_base_set(self, set: impl BaseSystemSet) -> SystemSetConfig { - self.into_config().in_base_set(set) - } - - fn in_default_base_set(self) -> SystemSetConfig { - self.into_config().in_default_base_set() - } - - fn before(self, set: impl IntoSystemSet) -> SystemSetConfig { - self.into_config().before(set) - } - - fn after(self, set: impl IntoSystemSet) -> SystemSetConfig { - self.into_config().after(set) - } - - fn run_if(self, condition: impl Condition) -> SystemSetConfig { - self.into_config().run_if(condition) - } - - fn ambiguous_with(self, set: impl IntoSystemSet) -> SystemSetConfig { - self.into_config().ambiguous_with(set) - } - - fn ambiguous_with_all(self) -> SystemSetConfig { - self.into_config().ambiguous_with_all() - } } impl IntoSystemSetConfig for BoxedSystemSet { fn into_config(self) -> SystemSetConfig { SystemSetConfig::new(self) } - - #[track_caller] - fn in_set(self, set: impl FreeSystemSet) -> SystemSetConfig { - self.into_config().in_set(set) - } - - #[track_caller] - fn in_base_set(self, set: impl BaseSystemSet) -> SystemSetConfig { - self.into_config().in_base_set(set) - } - - fn in_default_base_set(self) -> SystemSetConfig { - self.into_config().in_default_base_set() - } - - fn before(self, set: impl IntoSystemSet) -> SystemSetConfig { - self.into_config().before(set) - } - - fn after(self, set: impl IntoSystemSet) -> SystemSetConfig { - self.into_config().after(set) - } - - fn run_if(self, condition: impl Condition) -> SystemSetConfig { - self.into_config().run_if(condition) - } - - fn ambiguous_with(self, set: impl IntoSystemSet) -> SystemSetConfig { - self.into_config().ambiguous_with(set) - } - - fn ambiguous_with_all(self) -> SystemSetConfig { - self.into_config().ambiguous_with_all() - } } impl IntoSystemSetConfig for SystemSetConfig { @@ -273,33 +221,52 @@ impl IntoSystemSetConfig for SystemSetConfig { /// /// This has been implemented for boxed [`System`](crate::system::System) /// trait objects and all functions that turn into such. -pub trait IntoSystemConfig { +pub trait IntoSystemConfig: Sized +where + Config: IntoSystemConfig<(), Config>, +{ /// Convert into a [`SystemConfig`]. #[doc(hidden)] fn into_config(self) -> Config; /// Add to `set` membership. #[track_caller] - fn in_set(self, set: impl FreeSystemSet) -> Config; + fn in_set(self, set: impl FreeSystemSet) -> Config { + self.into_config().in_set(set) + } /// Add to the provided "base" `set`. For more information on base sets, see [`SystemSet::is_base`]. #[track_caller] - fn in_base_set(self, set: impl BaseSystemSet) -> Config; + fn in_base_set(self, set: impl BaseSystemSet) -> Config { + self.into_config().in_base_set(set) + } /// Don't add this system to the schedules's default set. - fn no_default_base_set(self) -> Config; + fn no_default_base_set(self) -> Config { + self.into_config().no_default_base_set() + } /// Run before all systems in `set`. - fn before(self, set: impl IntoSystemSet) -> Config; + fn before(self, set: impl IntoSystemSet) -> Config { + self.into_config().before(set) + } /// Run after all systems in `set`. - fn after(self, set: impl IntoSystemSet) -> Config; + fn after(self, set: impl IntoSystemSet) -> Config { + self.into_config().after(set) + } /// Run only if the [`Condition`] is `true`. /// /// The `Condition` will be evaluated at most once (per schedule run), /// when the system prepares to run. - fn run_if(self, condition: impl Condition) -> Config; + fn run_if(self, condition: impl Condition) -> Config { + self.into_config().run_if(condition) + } /// Suppress warnings and errors that would result from this system having ambiguities /// (conflicting access but indeterminate order) with systems in `set`. - fn ambiguous_with(self, set: impl IntoSystemSet) -> Config; + fn ambiguous_with(self, set: impl IntoSystemSet) -> Config { + self.into_config().ambiguous_with(set) + } /// Suppress warnings and errors that would result from this system having ambiguities /// (conflicting access but indeterminate order) with any other system. - fn ambiguous_with_all(self) -> Config; + fn ambiguous_with_all(self) -> Config { + self.into_config().ambiguous_with_all() + } } impl IntoSystemConfig for F @@ -309,80 +276,12 @@ where fn into_config(self) -> SystemConfig { SystemConfig::new(Box::new(IntoSystem::into_system(self))) } - - #[track_caller] - fn in_set(self, set: impl FreeSystemSet) -> SystemConfig { - self.into_config().in_set(set) - } - - #[track_caller] - fn in_base_set(self, set: impl BaseSystemSet) -> SystemConfig { - self.into_config().in_base_set(set) - } - - fn no_default_base_set(self) -> SystemConfig { - self.into_config().no_default_base_set() - } - - fn before(self, set: impl IntoSystemSet) -> SystemConfig { - self.into_config().before(set) - } - - fn after(self, set: impl IntoSystemSet) -> SystemConfig { - self.into_config().after(set) - } - - fn run_if(self, condition: impl Condition) -> SystemConfig { - self.into_config().run_if(condition) - } - - fn ambiguous_with(self, set: impl IntoSystemSet) -> SystemConfig { - self.into_config().ambiguous_with(set) - } - - fn ambiguous_with_all(self) -> SystemConfig { - self.into_config().ambiguous_with_all() - } } impl IntoSystemConfig<()> for BoxedSystem<(), ()> { fn into_config(self) -> SystemConfig { SystemConfig::new(self) } - - #[track_caller] - fn in_set(self, set: impl FreeSystemSet) -> SystemConfig { - self.into_config().in_set(set) - } - - #[track_caller] - fn in_base_set(self, set: impl BaseSystemSet) -> SystemConfig { - self.into_config().in_base_set(set) - } - - fn no_default_base_set(self) -> SystemConfig { - self.into_config().no_default_base_set() - } - - fn before(self, set: impl IntoSystemSet) -> SystemConfig { - self.into_config().before(set) - } - - fn after(self, set: impl IntoSystemSet) -> SystemConfig { - self.into_config().after(set) - } - - fn run_if(self, condition: impl Condition) -> SystemConfig { - self.into_config().run_if(condition) - } - - fn ambiguous_with(self, set: impl IntoSystemSet) -> SystemConfig { - self.into_config().ambiguous_with(set) - } - - fn ambiguous_with_all(self) -> SystemConfig { - self.into_config().ambiguous_with_all() - } } impl IntoSystemConfig<()> for SystemConfig {