pub trait Combine<A: System, B: System> {
type In: SystemInput;
type Out;
// Required method
fn combine<T>(
input: <Self::In as SystemInput>::Inner<'_>,
data: &mut T,
a: impl FnOnce(SystemIn<'_, A>, &mut T) -> Result<A::Out, RunSystemError>,
b: impl FnOnce(SystemIn<'_, B>, &mut T) -> Result<B::Out, RunSystemError>,
) -> Result<Self::Out, RunSystemError>;
}Expand description
Customizes the behavior of a CombinatorSystem.
§Examples
use bevy_ecs::prelude::*;
use bevy_ecs::system::{CombinatorSystem, Combine, RunSystemError};
// 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<T>(
_input: Self::In,
data: &mut T,
a: impl FnOnce(A::In, &mut T) -> Result<A::Out, RunSystemError>,
b: impl FnOnce(B::In, &mut T) -> Result<B::Out, RunSystemError>,
) -> Result<Self::Out, RunSystemError> {
Ok(a((), data).unwrap_or(false) ^ b((), data).unwrap_or(false))
}
}
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.
"a ^ b".into(),
)));Required Associated Types§
Sourcetype In: SystemInput
type In: SystemInput
The input type for a CombinatorSystem.
Sourcetype Out
type Out
The output type for a CombinatorSystem.
Required Methods§
Sourcefn combine<T>(
input: <Self::In as SystemInput>::Inner<'_>,
data: &mut T,
a: impl FnOnce(SystemIn<'_, A>, &mut T) -> Result<A::Out, RunSystemError>,
b: impl FnOnce(SystemIn<'_, B>, &mut T) -> Result<B::Out, RunSystemError>,
) -> Result<Self::Out, RunSystemError>
fn combine<T>( input: <Self::In as SystemInput>::Inner<'_>, data: &mut T, a: impl FnOnce(SystemIn<'_, A>, &mut T) -> Result<A::Out, RunSystemError>, b: impl FnOnce(SystemIn<'_, B>, &mut T) -> Result<B::Out, RunSystemError>, ) -> Result<Self::Out, RunSystemError>
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".