Skip to content

Commit f6dbc25

Browse files
committed
Optional .system(), part 6 (chaining) (#2494)
# Objective - Continue work of #2398 and friends. - Make `.system()` optional in chaining. ## Solution - Slight change to `IntoChainSystem` signature and implementation. - Remove some usages of `.system()` in the chaining example, to verify the implementation. --- I swear, I'm not splitting these up on purpose, I just legit forgot about most of the things where `System` appears in public API, and my trait usage explorer mingles that with the gajillion internal uses. In case you're wondering what happened to part 5, #2446 ate it.
1 parent c9c322e commit f6dbc25

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

crates/bevy_ecs/src/system/system_chaining.rs

+16-12
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::{
22
archetype::{Archetype, ArchetypeComponentId},
33
component::ComponentId,
44
query::Access,
5-
system::{System, SystemId},
5+
system::{IntoSystem, System, SystemId},
66
world::World,
77
};
88
use std::borrow::Cow;
@@ -29,7 +29,7 @@ use std::borrow::Cow;
2929
/// world.insert_resource(Message("42".to_string()));
3030
///
3131
/// // chain the `parse_message_system`'s output into the `filter_system`s input
32-
/// let mut chained_system = parse_message_system.system().chain(filter_system.system());
32+
/// let mut chained_system = parse_message_system.chain(filter_system);
3333
/// chained_system.initialize(&mut world);
3434
/// assert_eq!(chained_system.run((), &mut world), Some(42));
3535
/// }
@@ -118,25 +118,29 @@ impl<SystemA: System, SystemB: System<In = SystemA::Out>> System for ChainSystem
118118
/// This trait is blanket implemented for all system pairs that fulfill the chaining requirement.
119119
///
120120
/// See [`ChainSystem`].
121-
pub trait IntoChainSystem<SystemB>: System + Sized
121+
pub trait IntoChainSystem<ParamA, Payload, SystemB, ParamB, Out>:
122+
IntoSystem<(), Payload, ParamA> + Sized
122123
where
123-
SystemB: System<In = Self::Out>,
124+
SystemB: IntoSystem<Payload, Out, ParamB>,
124125
{
125126
/// Chain this system `A` with another system `B` creating a new system that feeds system A's
126127
/// output into system `B`, returning the output of system `B`.
127-
fn chain(self, system: SystemB) -> ChainSystem<Self, SystemB>;
128+
fn chain(self, system: SystemB) -> ChainSystem<Self::System, SystemB::System>;
128129
}
129130

130-
impl<SystemA, SystemB> IntoChainSystem<SystemB> for SystemA
131+
impl<SystemA, ParamA, Payload, SystemB, ParamB, Out>
132+
IntoChainSystem<ParamA, Payload, SystemB, ParamB, Out> for SystemA
131133
where
132-
SystemA: System,
133-
SystemB: System<In = SystemA::Out>,
134+
SystemA: IntoSystem<(), Payload, ParamA>,
135+
SystemB: IntoSystem<Payload, Out, ParamB>,
134136
{
135-
fn chain(self, system: SystemB) -> ChainSystem<SystemA, SystemB> {
137+
fn chain(self, system: SystemB) -> ChainSystem<SystemA::System, SystemB::System> {
138+
let system_a = self.system();
139+
let system_b = system.system();
136140
ChainSystem {
137-
name: Cow::Owned(format!("Chain({}, {})", self.name(), system.name())),
138-
system_a: self,
139-
system_b: system,
141+
name: Cow::Owned(format!("Chain({}, {})", system_a.name(), system_b.name())),
142+
system_a,
143+
system_b,
140144
archetype_component_access: Default::default(),
141145
component_access: Default::default(),
142146
id: SystemId::new(),

0 commit comments

Comments
 (0)