Trait bevy_ecs::system::Adapt

source ·
pub trait Adapt<S: System>: Send + Sync + 'static {
    type In;
    type Out;

    // Required method
    fn adapt(
        &mut self,
        input: Self::In,
        run_system: impl FnOnce(S::In) -> S::Out
    ) -> Self::Out;
}
Expand description

Customizes the behavior of an AdapterSystem

Examples

use bevy_ecs::system::{Adapt, AdapterSystem};

// A system adapter that inverts the result of a system.
// NOTE: Instead of manually implementing this, you can just use `bevy_ecs::schedule::common_conditions::not`.
pub type NotSystem<S> = AdapterSystem<NotMarker, S>;

// This struct is used to customize the behavior of our adapter.
pub struct NotMarker;

impl<S> Adapt<S> for NotMarker
where
    S: System,
    S::Out: std::ops::Not,
{
    type In = S::In;
    type Out = <S::Out as std::ops::Not>::Output;

    fn adapt(
        &mut self,
        input: Self::In,
        run_system: impl FnOnce(S::In) -> S::Out,
    ) -> Self::Out {
        !run_system(input)
    }
}

Required Associated Types§

source

type In

The input type for an AdapterSystem.

source

type Out

The output type for an AdapterSystem.

Required Methods§

source

fn adapt( &mut self, input: Self::In, run_system: impl FnOnce(S::In) -> S::Out ) -> Self::Out

When used in an AdapterSystem, this function customizes how the system is run and how its inputs/outputs are adapted.

Object Safety§

This trait is not object safe.

Implementors§

source§

impl<F, S, Out> Adapt<S> for F
where S: System, F: Send + Sync + 'static + FnMut(S::Out) -> Out,

§

type In = <S as System>::In

§

type Out = Out