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.
This commit is contained in:
Alexander Sepity 2021-07-17 19:14:18 +00:00
parent c9c322e820
commit f6dbc25bd9

View File

@ -2,7 +2,7 @@ use crate::{
archetype::{Archetype, ArchetypeComponentId}, archetype::{Archetype, ArchetypeComponentId},
component::ComponentId, component::ComponentId,
query::Access, query::Access,
system::{System, SystemId}, system::{IntoSystem, System, SystemId},
world::World, world::World,
}; };
use std::borrow::Cow; use std::borrow::Cow;
@ -29,7 +29,7 @@ use std::borrow::Cow;
/// world.insert_resource(Message("42".to_string())); /// world.insert_resource(Message("42".to_string()));
/// ///
/// // chain the `parse_message_system`'s output into the `filter_system`s input /// // 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); /// chained_system.initialize(&mut world);
/// assert_eq!(chained_system.run((), &mut world), Some(42)); /// assert_eq!(chained_system.run((), &mut world), Some(42));
/// } /// }
@ -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. /// This trait is blanket implemented for all system pairs that fulfill the chaining requirement.
/// ///
/// See [`ChainSystem`]. /// See [`ChainSystem`].
pub trait IntoChainSystem<SystemB>: System + Sized pub trait IntoChainSystem<ParamA, Payload, SystemB, ParamB, Out>:
IntoSystem<(), Payload, ParamA> + Sized
where 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 /// 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`. /// 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 where
SystemA: System, SystemA: IntoSystem<(), Payload, ParamA>,
SystemB: System<In = SystemA::Out>, 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 { ChainSystem {
name: Cow::Owned(format!("Chain({}, {})", self.name(), system.name())), name: Cow::Owned(format!("Chain({}, {})", system_a.name(), system_b.name())),
system_a: self, system_a,
system_b: system, system_b,
archetype_component_access: Default::default(), archetype_component_access: Default::default(),
component_access: Default::default(), component_access: Default::default(),
id: SystemId::new(), id: SystemId::new(),