Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Merged by Bors] - Optional .system(), part 6 (chaining) #2494

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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