From 3c05b7fdb8144bbeeb697e912927733a9b52db13 Mon Sep 17 00:00:00 2001 From: Daniel Liu Date: Thu, 14 Jul 2022 01:12:15 +0000 Subject: [PATCH] Add `assert_is_exclusive_system` function (#5275) Add compile time check for if a system is an exclusive system. Resolves #4788 Co-authored-by: Daniel Liu Co-authored-by: Daniel Liu --- crates/bevy_ecs/src/system/mod.rs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/crates/bevy_ecs/src/system/mod.rs b/crates/bevy_ecs/src/system/mod.rs index 6b18b2aa74164..17bd3b5a1a377 100644 --- a/crates/bevy_ecs/src/system/mod.rs +++ b/crates/bevy_ecs/src/system/mod.rs @@ -96,6 +96,34 @@ pub fn assert_is_system>(sys: S) } } +/// Ensure that a given function is an exclusive system +/// +/// This should be used when writing doc examples, +/// to confirm that systems used in an example are +/// valid exclusive systems +/// +/// Passing assert +/// ``` +/// # use bevy_ecs::prelude::World; +/// # use bevy_ecs::system::assert_is_exclusive_system; +/// fn an_exclusive_system(_world: &mut World) {} +/// +/// assert_is_exclusive_system(an_exclusive_system); +/// ``` +/// +/// Failing assert +/// ```compile_fail +/// # use bevy_ecs::prelude::World; +/// # use bevy_ecs::system::assert_is_exclusive_system; +/// fn not_an_exclusive_system(_world: &mut World, number: f32) {} +/// +/// assert_is_exclusive_system(not_an_exclusive_system); +/// ``` +pub fn assert_is_exclusive_system( + _sys: impl IntoExclusiveSystem, +) { +} + #[cfg(test)] mod tests { use std::any::TypeId;