diff --git a/crates/bevy_ecs/src/schedule/config.rs b/crates/bevy_ecs/src/schedule/config.rs index 899985fb22b43..54eb9f863f5b7 100644 --- a/crates/bevy_ecs/src/schedule/config.rs +++ b/crates/bevy_ecs/src/schedule/config.rs @@ -82,112 +82,60 @@ 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; - /// 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; - /// Add this set to the schedules's default base set. - fn in_default_base_set(self) -> SystemSetConfig; - /// Run before all systems in `set`. - fn before(self, set: impl IntoSystemSet) -> SystemSetConfig; - /// Run after all systems in `set`. - fn after(self, set: impl IntoSystemSet) -> SystemSetConfig; - /// 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; - /// 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; - /// 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; -} - -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) } - + /// 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 { self.into_config().in_base_set(set) } - + /// Add this set to the schedules's default base set. 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 { self.into_config().before(set) } - + /// Run after all systems in `set`. 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 { 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 { 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 { self.into_config().ambiguous_with_all() } } -impl IntoSystemSetConfig for BoxedSystemSet { +impl IntoSystemSetConfig for S { 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) + SystemSetConfig::new(Box::new(self)) } +} - fn ambiguous_with_all(self) -> SystemSetConfig { - self.into_config().ambiguous_with_all() +impl IntoSystemSetConfig for BoxedSystemSet { + fn into_config(self) -> SystemSetConfig { + SystemSetConfig::new(self) } } @@ -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 {