From 53b2e4facfde844202c88e81c632c9c7e2adf27a Mon Sep 17 00:00:00 2001 From: Ratys Date: Thu, 1 Jul 2021 19:34:46 +0300 Subject: [PATCH 1/2] Enable omitting `.system()` with `.config()`. --- crates/bevy_ecs/src/lib.rs | 4 +-- crates/bevy_ecs/src/system/function_system.rs | 34 +++++++++++++++++++ crates/bevy_ecs/src/system/mod.rs | 10 ++++-- 3 files changed, 44 insertions(+), 4 deletions(-) diff --git a/crates/bevy_ecs/src/lib.rs b/crates/bevy_ecs/src/lib.rs index a6fdbced0894d..d95a15bd0804b 100644 --- a/crates/bevy_ecs/src/lib.rs +++ b/crates/bevy_ecs/src/lib.rs @@ -29,8 +29,8 @@ pub mod prelude { Schedule, Stage, StageLabel, State, SystemLabel, SystemSet, SystemStage, }, system::{ - Commands, In, IntoChainSystem, IntoExclusiveSystem, IntoSystem, Local, NonSend, - NonSendMut, Query, QuerySet, RemovedComponents, Res, ResMut, System, + Commands, ConfigurableSystem, In, IntoChainSystem, IntoExclusiveSystem, IntoSystem, + Local, NonSend, NonSendMut, Query, QuerySet, RemovedComponents, Res, ResMut, System, }, world::{FromWorld, Mut, World}, }; diff --git a/crates/bevy_ecs/src/system/function_system.rs b/crates/bevy_ecs/src/system/function_system.rs index 566ef78dbf9c7..aa33ce386dcfc 100644 --- a/crates/bevy_ecs/src/system/function_system.rs +++ b/crates/bevy_ecs/src/system/function_system.rs @@ -263,6 +263,40 @@ impl FunctionSystem: + IntoSystem +{ + fn config( + self, + f: impl FnOnce(&mut ::Config), + ) -> Self::System; +} + +impl ConfigurableSystem for F +where + In: 'static, + Out: 'static, + Param: SystemParam + 'static, + Marker: 'static, + F: SystemParamFunction + + IntoSystem< + In, + Out, + (IsFunctionSystem, Param, Marker), + System = FunctionSystem, + > + Send + + Sync + + 'static, +{ + fn config( + self, + f: impl FnOnce(&mut <::Fetch as SystemParamState>::Config), + ) -> Self::System { + self.system().config(f) + } +} + pub struct IsFunctionSystem; impl IntoSystem for F diff --git a/crates/bevy_ecs/src/system/mod.rs b/crates/bevy_ecs/src/system/mod.rs index c05dfc7f80b3c..2110bad7520c9 100644 --- a/crates/bevy_ecs/src/system/mod.rs +++ b/crates/bevy_ecs/src/system/mod.rs @@ -27,8 +27,8 @@ mod tests { query::{Added, Changed, Or, With, Without}, schedule::{Schedule, Stage, SystemStage}, system::{ - IntoExclusiveSystem, IntoSystem, Local, Query, QuerySet, RemovedComponents, Res, - ResMut, System, SystemState, + ConfigurableSystem, IntoExclusiveSystem, IntoSystem, Local, Query, QuerySet, + RemovedComponents, Res, ResMut, System, SystemState, }, world::{FromWorld, World}, }; @@ -372,7 +372,13 @@ mod tests { // ensure the system actually ran assert!(*world.get_resource::().unwrap()); + + // Now do the same with omitted `.system()`. + world.insert_resource(false); + run_system(&mut world, sys.config(|config| config.0 = Some(42))); + assert!(*world.get_resource::().unwrap()); } + #[test] fn world_collections_system() { let mut world = World::default(); From 97f0449d54bb7ea1529a779cd29da4ce7baef967 Mon Sep 17 00:00:00 2001 From: Ratys Date: Thu, 1 Jul 2021 19:46:43 +0300 Subject: [PATCH 2/2] Documented `ConfigurableSystem`. --- crates/bevy_ecs/src/system/function_system.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/crates/bevy_ecs/src/system/function_system.rs b/crates/bevy_ecs/src/system/function_system.rs index aa33ce386dcfc..a8de42abf54f9 100644 --- a/crates/bevy_ecs/src/system/function_system.rs +++ b/crates/bevy_ecs/src/system/function_system.rs @@ -264,9 +264,11 @@ impl FunctionSystem: IntoSystem { + /// See [`FunctionSystem::config()`](crate::system::FunctionSystem::config). fn config( self, f: impl FnOnce(&mut ::Config),