diff --git a/crates/bevy_ecs/src/system/system_piping.rs b/crates/bevy_ecs/src/system/system_piping.rs index 4787fccd469d06..7bf8f3c7044707 100644 --- a/crates/bevy_ecs/src/system/system_piping.rs +++ b/crates/bevy_ecs/src/system/system_piping.rs @@ -199,7 +199,7 @@ where pub mod adapter { use crate::system::In; use bevy_utils::tracing; - use std::fmt::Debug; + use std::{fmt::Debug, ops::Not}; /// Converts a regular function into a system adapter. /// @@ -406,6 +406,34 @@ pub mod adapter { /// ``` pub fn ignore(In(_): In) {} + /// System adapter that inverts the output of the previous system in a pipe. + /// + /// # Examples + /// + /// ``` + /// use bevy_ecs::prelude::*; + /// // Building a new schedule/app... + /// let mut sched = Schedule::default(); + /// sched.add_system( + /// // This system will always run. + /// my_system.run_if(always_false.pipe(system_adapter::negate)) + /// ) + /// // ... + /// # ; + /// # let mut world = World::new(); + /// # sched.run(&mut world); + /// + /// // A condition that always returns false. + /// fn always_false() -> bool { + /// false + /// } + /// + /// # fn my_system() {} + /// ``` + pub fn negate(In(val): In) -> T { + !val + } + #[cfg(test)] #[test] fn assert_systems() { @@ -423,16 +451,12 @@ pub mod adapter { unimplemented!() } - fn not(In(val): In) -> bool { - !val - } - assert_is_system(returning::>.pipe(unwrap)); assert_is_system(returning::>.pipe(ignore)); assert_is_system(returning::<&str>.pipe(new(u64::from_str)).pipe(unwrap)); assert_is_system(exclusive_in_out::<(), Result<(), std::io::Error>>.pipe(error)); assert_is_system(returning::.pipe(exclusive_in_out::)); - returning::<()>.run_if(returning::.pipe(not)); + returning::<()>.run_if(returning::.pipe(negate)); } }