pub trait Combine<A: System, B: System> {
type In;
type Out;
// Required method
fn combine(
input: Self::In,
a: impl FnOnce(A::In) -> A::Out,
b: impl FnOnce(B::In) -> B::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§
Sourcetype In
type In
The input type for a CombinatorSystem
.
Sourcetype Out
type Out
The output type for a CombinatorSystem
.
Required Methods§
Sourcefn combine(
input: Self::In,
a: impl FnOnce(A::In) -> A::Out,
b: impl FnOnce(B::In) -> B::Out,
) -> Self::Out
fn combine( input: Self::In, a: impl FnOnce(A::In) -> A::Out, b: impl FnOnce(B::In) -> B::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.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.