diff --git a/crates/bevy_ecs/src/schedule/system_descriptor.rs b/crates/bevy_ecs/src/schedule/system_descriptor.rs index 74a3963ca2..6f470076bf 100644 --- a/crates/bevy_ecs/src/schedule/system_descriptor.rs +++ b/crates/bevy_ecs/src/schedule/system_descriptor.rs @@ -78,7 +78,10 @@ impl IntoSystemDescriptor<()> for ExclusiveSystemDescriptor { } } -impl IntoSystemDescriptor<()> for ExclusiveSystemFn { +impl IntoSystemDescriptor<()> for ExclusiveSystemFn +where + F: FnMut(&mut crate::prelude::World) + Send + Sync + 'static, +{ fn into_descriptor(self) -> SystemDescriptor { new_exclusive_descriptor(Box::new(self)).into_descriptor() } diff --git a/crates/bevy_ecs/src/system/exclusive_system.rs b/crates/bevy_ecs/src/system/exclusive_system.rs index 42dfb16c4c..1d7902650d 100644 --- a/crates/bevy_ecs/src/system/exclusive_system.rs +++ b/crates/bevy_ecs/src/system/exclusive_system.rs @@ -15,13 +15,16 @@ pub trait ExclusiveSystem: Send + Sync + 'static { fn check_change_tick(&mut self, change_tick: u32); } -pub struct ExclusiveSystemFn { - func: Box, +pub struct ExclusiveSystemFn { + func: F, name: Cow<'static, str>, last_change_tick: u32, } -impl ExclusiveSystem for ExclusiveSystemFn { +impl ExclusiveSystem for ExclusiveSystemFn +where + F: FnMut(&mut World) + Send + Sync + 'static, +{ fn name(&self) -> Cow<'static, str> { self.name.clone() } @@ -52,13 +55,13 @@ pub trait IntoExclusiveSystem { fn exclusive_system(self) -> SystemType; } -impl IntoExclusiveSystem<&mut World, ExclusiveSystemFn> for F +impl IntoExclusiveSystem<&mut World, ExclusiveSystemFn> for F where F: FnMut(&mut World) + Send + Sync + 'static, { - fn exclusive_system(self) -> ExclusiveSystemFn { + fn exclusive_system(self) -> ExclusiveSystemFn { ExclusiveSystemFn { - func: Box::new(self), + func: self, name: core::any::type_name::().into(), last_change_tick: 0, }