Skip to main content

Adapt

Trait Adapt 

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

    // Required method
    fn adapt(
        &mut self,
        input: <Self::In as SystemInput>::Inner<'_>,
        run_system: impl FnOnce(SystemIn<'_, S>) -> Result<S::Out, RunSystemError>,
    ) -> Result<Self::Out, RunSystemError>;
}
Expand description

Customizes the behavior of an AdapterSystem

§Examples

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

// 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 as SystemInput>::Inner<'_>,
        run_system: impl FnOnce(SystemIn<'_, S>) -> Result<S::Out, RunSystemError>,
    ) -> Result<Self::Out, RunSystemError> {
        let result = run_system(input)?;
        Ok(!result)
    }
}

Required Associated Types§

Source

type In: SystemInput

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 as SystemInput>::Inner<'_>, run_system: impl FnOnce(SystemIn<'_, S>) -> Result<S::Out, RunSystemError>, ) -> Result<Self::Out, RunSystemError>

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

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

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

Source§

type In = <S as System>::In

Source§

type Out = Out