Skip to content

Commit

Permalink
Optional .system(), part 6 (chaining) (#2494)
Browse files Browse the repository at this point in the history
# 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.
  • Loading branch information
Ratysz committed Jul 17, 2021
1 parent c9c322e commit f6dbc25
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions crates/bevy_ecs/src/system/system_chaining.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::{
archetype::{Archetype, ArchetypeComponentId},
component::ComponentId,
query::Access,
system::{System, SystemId},
system::{IntoSystem, System, SystemId},
world::World,
};
use std::borrow::Cow;
Expand All @@ -29,7 +29,7 @@ use std::borrow::Cow;
/// world.insert_resource(Message("42".to_string()));
///
/// // chain the `parse_message_system`'s output into the `filter_system`s input
/// let mut chained_system = parse_message_system.system().chain(filter_system.system());
/// let mut chained_system = parse_message_system.chain(filter_system);
/// chained_system.initialize(&mut world);
/// assert_eq!(chained_system.run((), &mut world), Some(42));
/// }
Expand Down Expand Up @@ -118,25 +118,29 @@ impl<SystemA: System, SystemB: System<In = SystemA::Out>> System for ChainSystem
/// This trait is blanket implemented for all system pairs that fulfill the chaining requirement.
///
/// See [`ChainSystem`].
pub trait IntoChainSystem<SystemB>: System + Sized
pub trait IntoChainSystem<ParamA, Payload, SystemB, ParamB, Out>:
IntoSystem<(), Payload, ParamA> + Sized
where
SystemB: System<In = Self::Out>,
SystemB: IntoSystem<Payload, Out, ParamB>,
{
/// Chain this system `A` with another system `B` creating a new system that feeds system A's
/// output into system `B`, returning the output of system `B`.
fn chain(self, system: SystemB) -> ChainSystem<Self, SystemB>;
fn chain(self, system: SystemB) -> ChainSystem<Self::System, SystemB::System>;
}

impl<SystemA, SystemB> IntoChainSystem<SystemB> for SystemA
impl<SystemA, ParamA, Payload, SystemB, ParamB, Out>
IntoChainSystem<ParamA, Payload, SystemB, ParamB, Out> for SystemA
where
SystemA: System,
SystemB: System<In = SystemA::Out>,
SystemA: IntoSystem<(), Payload, ParamA>,
SystemB: IntoSystem<Payload, Out, ParamB>,
{
fn chain(self, system: SystemB) -> ChainSystem<SystemA, SystemB> {
fn chain(self, system: SystemB) -> ChainSystem<SystemA::System, SystemB::System> {
let system_a = self.system();
let system_b = system.system();
ChainSystem {
name: Cow::Owned(format!("Chain({}, {})", self.name(), system.name())),
system_a: self,
system_b: system,
name: Cow::Owned(format!("Chain({}, {})", system_a.name(), system_b.name())),
system_a,
system_b,
archetype_component_access: Default::default(),
component_access: Default::default(),
id: SystemId::new(),
Expand Down

0 comments on commit f6dbc25

Please sign in to comment.