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},
component::ComponentId,
query::Access,
system::{System, SystemId},
system::{IntoSystem, System, SystemId},
world::World,
};
use std::borrow::Cow;
@ -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));
/// }
@ -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(),