pub trait Combine<A, B>
where A: System, B: System,
{ type In; type Out; // Required method fn combine( input: Self::In, a: impl FnOnce(<A as System>::In) -> <A as System>::Out, b: impl FnOnce(<B as System>::In) -> <B as System>::Out ) -> Self::Out; }
Expand description

Customizes the behavior of a CombinatorSystem.

Examples

use bevy_ecs::prelude::*;
use bevy_ecs::system::{CombinatorSystem, Combine};

// A system combinator that performs an exclusive-or (XOR)
// operation on the output of two systems.
pub type Xor<A, B> = CombinatorSystem<XorMarker, A, B>;

// This struct is used to customize the behavior of our combinator.
pub struct XorMarker;

impl<A, B> Combine<A, B> for XorMarker
where
    A: System<In = (), Out = bool>,
    B: System<In = (), Out = bool>,
{
    type In = ();
    type Out = bool;

    fn combine(
        _input: Self::In,
        a: impl FnOnce(A::In) -> A::Out,
        b: impl FnOnce(B::In) -> B::Out,
    ) -> Self::Out {
        a(()) ^ b(())
    }
}

app.add_systems(my_system.run_if(Xor::new(
    IntoSystem::into_system(resource_equals(A(1))),
    IntoSystem::into_system(resource_equals(B(1))),
    // The name of the combined system.
    std::borrow::Cow::Borrowed("a ^ b"),
)));

Required Associated Types§

source

type In

The input type for a CombinatorSystem.

source

type Out

The output type for a CombinatorSystem.

Required Methods§

source

fn combine( input: Self::In, a: impl FnOnce(<A as System>::In) -> <A as System>::Out, b: impl FnOnce(<B as System>::In) -> <B as System>::Out ) -> Self::Out

When used in a CombinatorSystem, this function customizes how the two composite systems are invoked and their outputs are combined.

See the trait-level docs for Combine for an example implementation.

Object Safety§

This trait is not object safe.

Implementors§