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 <mr.picklepinosaur@gmail.com>
Co-authored-by: Daniel Liu <danieliu3120@gmail.com>
This commit is contained in:
Daniel Liu 2022-07-14 01:12:15 +00:00
parent b3d15153f3
commit fe59fe5860

View file

@ -96,6 +96,34 @@ pub fn assert_is_system<In, Out, Params, S: IntoSystem<In, Out, Params>>(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<Params, SystemType>(
_sys: impl IntoExclusiveSystem<Params, SystemType>,
) {
}
#[cfg(test)]
mod tests {
use std::any::TypeId;