From e1c7f832a162871d1467ea469422c849c15d66a2 Mon Sep 17 00:00:00 2001 From: Aidan Grant Date: Thu, 31 Aug 2023 20:56:11 -0600 Subject: [PATCH 1/2] Cleaned up CallbackSystem::run method --- .../bevy_eventlistener_core/src/callbacks.rs | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/crates/bevy_eventlistener_core/src/callbacks.rs b/crates/bevy_eventlistener_core/src/callbacks.rs index 08fa2e3..e3c0dd7 100644 --- a/crates/bevy_eventlistener_core/src/callbacks.rs +++ b/crates/bevy_eventlistener_core/src/callbacks.rs @@ -16,18 +16,17 @@ impl CallbackSystem { } pub(crate) fn run(&mut self, world: &mut World) { - if !self.is_initialized() { - let mut temp = CallbackSystem::Empty; - std::mem::swap(self, &mut temp); - if let CallbackSystem::New(mut system) = temp { + let mut system = match std::mem::take(self) { + CallbackSystem::Empty => {return} + CallbackSystem::New(mut system) => { system.initialize(world); - *self = CallbackSystem::Initialized(system); + system } - } - if let CallbackSystem::Initialized(system) = self { - system.run((), world); - system.apply_deferred(world); - } + CallbackSystem::Initialized(system) => system + }; + system.run((), world); + system.apply_deferred(world); + *self = CallbackSystem::Initialized(system); } } From e9c02b11206bd5a0138c372eb38e1c1273dcdd31 Mon Sep 17 00:00:00 2001 From: Aevyrie Date: Sun, 29 Oct 2023 20:04:33 -0700 Subject: [PATCH 2/2] fix formatting and remove unused fn --- crates/bevy_eventlistener_core/src/callbacks.rs | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/crates/bevy_eventlistener_core/src/callbacks.rs b/crates/bevy_eventlistener_core/src/callbacks.rs index e3c0dd7..0779fc1 100644 --- a/crates/bevy_eventlistener_core/src/callbacks.rs +++ b/crates/bevy_eventlistener_core/src/callbacks.rs @@ -11,18 +11,14 @@ pub enum CallbackSystem { } impl CallbackSystem { - pub(crate) fn is_initialized(&self) -> bool { - matches!(self, CallbackSystem::Initialized(_)) - } - pub(crate) fn run(&mut self, world: &mut World) { let mut system = match std::mem::take(self) { - CallbackSystem::Empty => {return} + CallbackSystem::Empty => return, CallbackSystem::New(mut system) => { system.initialize(world); system } - CallbackSystem::Initialized(system) => system + CallbackSystem::Initialized(system) => system, }; system.run((), world); system.apply_deferred(world);