From 626dd7bad904f37523e8817fa2e344066c7c7b28 Mon Sep 17 00:00:00 2001 From: JoJoJet <21144246+JoJoJet@users.noreply.github.com> Date: Thu, 13 Apr 2023 14:32:19 -0400 Subject: [PATCH 1/5] make system piping more flexible --- crates/bevy_ecs/src/system/system_piping.rs | 24 +++++++++++---------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/crates/bevy_ecs/src/system/system_piping.rs b/crates/bevy_ecs/src/system/system_piping.rs index dc1f3dc55a658..eb12fd4f90f6d 100644 --- a/crates/bevy_ecs/src/system/system_piping.rs +++ b/crates/bevy_ecs/src/system/system_piping.rs @@ -73,22 +73,24 @@ where /// This trait is blanket implemented for all system pairs that fulfill the type requirements. /// /// See [`PipeSystem`]. -pub trait IntoPipeSystem: - IntoSystem<(), Payload, ParamA> + Sized -where - SystemB: IntoSystem, -{ +pub trait IntoPipeSystem: IntoSystem + Sized { /// Pass the output of this system `A` into a second system `B`, creating a new compound system. - fn pipe(self, system: SystemB) -> PipeSystem; + fn pipe(self, system: B) -> PipeSystem + where + B: IntoSystem; } -impl - IntoPipeSystem for SystemA +impl IntoPipeSystem for SystemA where - SystemA: IntoSystem<(), Payload, ParamA>, - SystemB: IntoSystem, + SystemA: IntoSystem, { - fn pipe(self, system: SystemB) -> PipeSystem { + fn pipe( + self, + system: SystemB, + ) -> PipeSystem + where + SystemB: IntoSystem, + { let system_a = IntoSystem::into_system(self); let system_b = IntoSystem::into_system(system); let name = format!("Pipe({}, {})", system_a.name(), system_b.name()); From 0baa9fde0747854eda32b35a79da1985ce0c1ed6 Mon Sep 17 00:00:00 2001 From: JoJoJet <21144246+JoJoJet@users.noreply.github.com> Date: Thu, 13 Apr 2023 14:48:41 -0400 Subject: [PATCH 2/5] use a default implementation for `pipe` --- crates/bevy_ecs/src/system/system_piping.rs | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/crates/bevy_ecs/src/system/system_piping.rs b/crates/bevy_ecs/src/system/system_piping.rs index eb12fd4f90f6d..28529d0e03305 100644 --- a/crates/bevy_ecs/src/system/system_piping.rs +++ b/crates/bevy_ecs/src/system/system_piping.rs @@ -77,19 +77,7 @@ pub trait IntoPipeSystem: IntoSystem + /// Pass the output of this system `A` into a second system `B`, creating a new compound system. fn pipe(self, system: B) -> PipeSystem where - B: IntoSystem; -} - -impl IntoPipeSystem for SystemA -where - SystemA: IntoSystem, -{ - fn pipe( - self, - system: SystemB, - ) -> PipeSystem - where - SystemB: IntoSystem, + B: IntoSystem, { let system_a = IntoSystem::into_system(self); let system_b = IntoSystem::into_system(system); @@ -98,6 +86,11 @@ where } } +impl IntoPipeSystem for SystemA where + SystemA: IntoSystem +{ +} + /// A collection of common adapters for [piping](super::PipeSystem) the result of a system. pub mod adapter { use crate::system::In; From 647b9ef9763373693d00ec111e295841143285f2 Mon Sep 17 00:00:00 2001 From: JoJoJet <21144246+JoJoJet@users.noreply.github.com> Date: Thu, 13 Apr 2023 14:50:03 -0400 Subject: [PATCH 3/5] simplify names --- crates/bevy_ecs/src/system/system_piping.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/bevy_ecs/src/system/system_piping.rs b/crates/bevy_ecs/src/system/system_piping.rs index 28529d0e03305..7f645168af7f9 100644 --- a/crates/bevy_ecs/src/system/system_piping.rs +++ b/crates/bevy_ecs/src/system/system_piping.rs @@ -86,8 +86,8 @@ pub trait IntoPipeSystem: IntoSystem + } } -impl IntoPipeSystem for SystemA where - SystemA: IntoSystem +impl IntoPipeSystem for Sys where + Sys: IntoSystem { } From fbc8790b382392b77560c62abb3868ab85ea423a Mon Sep 17 00:00:00 2001 From: JoJoJet <21144246+JoJoJet@users.noreply.github.com> Date: Thu, 13 Apr 2023 14:52:20 -0400 Subject: [PATCH 4/5] remove a workaround --- crates/bevy_ecs/src/system/system_piping.rs | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/crates/bevy_ecs/src/system/system_piping.rs b/crates/bevy_ecs/src/system/system_piping.rs index e26fd70613721..5712347c5da70 100644 --- a/crates/bevy_ecs/src/system/system_piping.rs +++ b/crates/bevy_ecs/src/system/system_piping.rs @@ -308,7 +308,7 @@ mod tests { use bevy_utils::default; use super::adapter::*; - use crate::{self as bevy_ecs, prelude::*, system::PipeSystem}; + use crate::{self as bevy_ecs, prelude::*}; #[test] fn assert_systems() { @@ -379,11 +379,7 @@ mod tests { let mut world = World::new(); world.init_resource::(); - let mut sys = PipeSystem::new( - IntoSystem::into_system(first), - IntoSystem::into_system(second), - "".into(), - ); + let mut sys = first.pipe(second); sys.initialize(&mut world); sys.run(default(), &mut world); From 7ec9683060006d2b13862b5a42e49baf65b3171b Mon Sep 17 00:00:00 2001 From: JoJoJet <21144246+JoJoJet@users.noreply.github.com> Date: Thu, 13 Apr 2023 19:27:59 -0400 Subject: [PATCH 5/5] merge `IntoPipeSystem` with `IntoSystem` --- crates/bevy_ecs/src/lib.rs | 4 +-- crates/bevy_ecs/src/system/function_system.rs | 16 +++++++++- crates/bevy_ecs/src/system/system_piping.rs | 29 +------------------ 3 files changed, 18 insertions(+), 31 deletions(-) diff --git a/crates/bevy_ecs/src/lib.rs b/crates/bevy_ecs/src/lib.rs index a5967a73ab2b8..2e531493ebf77 100644 --- a/crates/bevy_ecs/src/lib.rs +++ b/crates/bevy_ecs/src/lib.rs @@ -46,8 +46,8 @@ pub mod prelude { system::{ adapter as system_adapter, adapter::{dbg, error, ignore, info, unwrap, warn}, - Commands, Deferred, In, IntoPipeSystem, IntoSystem, Local, NonSend, NonSendMut, - ParallelCommands, ParamSet, Query, Res, ResMut, Resource, System, SystemParamFunction, + Commands, Deferred, In, IntoSystem, Local, NonSend, NonSendMut, ParallelCommands, + ParamSet, Query, Res, ResMut, Resource, System, SystemParamFunction, }, world::{FromWorld, World}, }; diff --git a/crates/bevy_ecs/src/system/function_system.rs b/crates/bevy_ecs/src/system/function_system.rs index a56e5d85fe119..47f984e415136 100644 --- a/crates/bevy_ecs/src/system/function_system.rs +++ b/crates/bevy_ecs/src/system/function_system.rs @@ -10,7 +10,7 @@ use crate::{ use bevy_utils::all_tuples; use std::{any::TypeId, borrow::Cow, marker::PhantomData}; -use super::ReadOnlySystem; +use super::{PipeSystem, ReadOnlySystem}; /// The metadata of a [`System`]. #[derive(Clone)] @@ -329,6 +329,20 @@ pub trait IntoSystem: Sized { type System: System; /// Turns this value into its corresponding [`System`]. fn into_system(this: Self) -> Self::System; + + /// Pass the output of this system `A` into a second system `B`, creating a new compound system. + /// + /// The second system must have `In` as its first parameter, where `T` + /// is the return type of the first system. + fn pipe(self, system: B) -> PipeSystem + where + B: IntoSystem, + { + let system_a = IntoSystem::into_system(self); + let system_b = IntoSystem::into_system(system); + let name = format!("Pipe({}, {})", system_a.name(), system_b.name()); + PipeSystem::new(system_a, system_b, Cow::Owned(name)) + } } // Systems implicitly implement IntoSystem diff --git a/crates/bevy_ecs/src/system/system_piping.rs b/crates/bevy_ecs/src/system/system_piping.rs index 5712347c5da70..8acb9a352f069 100644 --- a/crates/bevy_ecs/src/system/system_piping.rs +++ b/crates/bevy_ecs/src/system/system_piping.rs @@ -1,5 +1,4 @@ -use crate::system::{IntoSystem, System}; -use std::borrow::Cow; +use crate::system::System; use super::{CombinatorSystem, Combine}; @@ -65,32 +64,6 @@ where } } -/// An extension trait providing the [`IntoPipeSystem::pipe`] method to pass input from one system into the next. -/// -/// The first system must have return type `T` -/// and the second system must have [`In`](crate::system::In) as its first system parameter. -/// -/// This trait is blanket implemented for all system pairs that fulfill the type requirements. -/// -/// See [`PipeSystem`]. -pub trait IntoPipeSystem: IntoSystem + Sized { - /// Pass the output of this system `A` into a second system `B`, creating a new compound system. - fn pipe(self, system: B) -> PipeSystem - where - B: IntoSystem, - { - let system_a = IntoSystem::into_system(self); - let system_b = IntoSystem::into_system(system); - let name = format!("Pipe({}, {})", system_a.name(), system_b.name()); - PipeSystem::new(system_a, system_b, Cow::Owned(name)) - } -} - -impl IntoPipeSystem for Sys where - Sys: IntoSystem -{ -} - /// A collection of common adapters for [piping](super::PipeSystem) the result of a system. pub mod adapter { use crate::system::In;