From 530d9516707e60151bc660ef862b9c8b81384fd3 Mon Sep 17 00:00:00 2001 From: JoJoJet Date: Thu, 11 Aug 2022 20:48:38 -0400 Subject: [PATCH 1/2] remove an outdated workaround --- crates/bevy_ecs/src/schedule/mod.rs | 21 ++++++++++----------- crates/bevy_render/src/lib.rs | 12 ++++++------ 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/crates/bevy_ecs/src/schedule/mod.rs b/crates/bevy_ecs/src/schedule/mod.rs index 2e1bd167caedf..7d62df5588be6 100644 --- a/crates/bevy_ecs/src/schedule/mod.rs +++ b/crates/bevy_ecs/src/schedule/mod.rs @@ -211,9 +211,10 @@ impl Schedule { ) } + let stage_label = stage_label.as_label(); let stage = self - .get_stage_mut::(&stage_label) - .unwrap_or_else(move || stage_not_found(&stage_label.as_label())); + .get_stage_mut::(stage_label) + .unwrap_or_else(move || stage_not_found(&stage_label)); stage.add_system(system); self } @@ -281,11 +282,9 @@ impl Schedule { label: impl StageLabel, func: F, ) -> &mut Self { - let stage = self.get_stage_mut::(&label).unwrap_or_else(move || { - panic!( - "stage '{:?}' does not exist or is the wrong type", - label.as_label() - ) + let label = label.as_label(); + let stage = self.get_stage_mut::(label).unwrap_or_else(move || { + panic!("stage '{label:?}' does not exist or is the wrong type",) }); func(stage); self @@ -304,9 +303,9 @@ impl Schedule { /// # let mut schedule = Schedule::default(); /// # schedule.add_stage("my_stage", SystemStage::parallel()); /// # - /// let stage = schedule.get_stage::(&"my_stage").unwrap(); + /// let stage = schedule.get_stage::("my_stage").unwrap(); /// ``` - pub fn get_stage(&self, label: &dyn StageLabel) -> Option<&T> { + pub fn get_stage(&self, label: impl StageLabel) -> Option<&T> { self.stages .get(&label.as_label()) .and_then(|stage| stage.downcast_ref::()) @@ -325,9 +324,9 @@ impl Schedule { /// # let mut schedule = Schedule::default(); /// # schedule.add_stage("my_stage", SystemStage::parallel()); /// # - /// let stage = schedule.get_stage_mut::(&"my_stage").unwrap(); + /// let stage = schedule.get_stage_mut::("my_stage").unwrap(); /// ``` - pub fn get_stage_mut(&mut self, label: &dyn StageLabel) -> Option<&mut T> { + pub fn get_stage_mut(&mut self, label: impl StageLabel) -> Option<&mut T> { self.stages .get_mut(&label.as_label()) .and_then(|stage| stage.downcast_mut::()) diff --git a/crates/bevy_render/src/lib.rs b/crates/bevy_render/src/lib.rs index 5efbb5ba9c03a..fbe5f14923970 100644 --- a/crates/bevy_render/src/lib.rs +++ b/crates/bevy_render/src/lib.rs @@ -249,7 +249,7 @@ impl Plugin for RenderPlugin { // prepare let prepare = render_app .schedule - .get_stage_mut::(&RenderStage::Prepare) + .get_stage_mut::(RenderStage::Prepare) .unwrap(); prepare.run(&mut render_app.world); } @@ -262,7 +262,7 @@ impl Plugin for RenderPlugin { // queue let queue = render_app .schedule - .get_stage_mut::(&RenderStage::Queue) + .get_stage_mut::(RenderStage::Queue) .unwrap(); queue.run(&mut render_app.world); } @@ -275,7 +275,7 @@ impl Plugin for RenderPlugin { // phase sort let phase_sort = render_app .schedule - .get_stage_mut::(&RenderStage::PhaseSort) + .get_stage_mut::(RenderStage::PhaseSort) .unwrap(); phase_sort.run(&mut render_app.world); } @@ -288,7 +288,7 @@ impl Plugin for RenderPlugin { // render let render = render_app .schedule - .get_stage_mut::(&RenderStage::Render) + .get_stage_mut::(RenderStage::Render) .unwrap(); render.run(&mut render_app.world); } @@ -301,7 +301,7 @@ impl Plugin for RenderPlugin { // cleanup let cleanup = render_app .schedule - .get_stage_mut::(&RenderStage::Cleanup) + .get_stage_mut::(RenderStage::Cleanup) .unwrap(); cleanup.run(&mut render_app.world); } @@ -335,7 +335,7 @@ struct ScratchMainWorld(World); fn extract(app_world: &mut World, render_app: &mut App) { let extract = render_app .schedule - .get_stage_mut::(&RenderStage::Extract) + .get_stage_mut::(RenderStage::Extract) .unwrap(); // temporarily add the app world to the render world as a resource From ae2916a81496a3bf28580ba98b7c698c83672cf8 Mon Sep 17 00:00:00 2001 From: JoJoJet Date: Sat, 13 Aug 2022 17:32:36 -0400 Subject: [PATCH 2/2] Apply suggestions from code review --- crates/bevy_ecs/src/schedule/mod.rs | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/crates/bevy_ecs/src/schedule/mod.rs b/crates/bevy_ecs/src/schedule/mod.rs index 7d62df5588be6..0ac1e8702d685 100644 --- a/crates/bevy_ecs/src/schedule/mod.rs +++ b/crates/bevy_ecs/src/schedule/mod.rs @@ -211,10 +211,10 @@ impl Schedule { ) } - let stage_label = stage_label.as_label(); + let label = stage_label.as_label(); let stage = self - .get_stage_mut::(stage_label) - .unwrap_or_else(move || stage_not_found(&stage_label)); + .get_stage_mut::(label) + .unwrap_or_else(move || stage_not_found(&label)); stage.add_system(system); self } @@ -279,10 +279,10 @@ impl Schedule { /// Panics if `label` refers to a non-existing stage, or if it's not of type `T`. pub fn stage &mut T>( &mut self, - label: impl StageLabel, + stage_label: impl StageLabel, func: F, ) -> &mut Self { - let label = label.as_label(); + let label = stage_label.as_label(); let stage = self.get_stage_mut::(label).unwrap_or_else(move || { panic!("stage '{label:?}' does not exist or is the wrong type",) }); @@ -305,9 +305,10 @@ impl Schedule { /// # /// let stage = schedule.get_stage::("my_stage").unwrap(); /// ``` - pub fn get_stage(&self, label: impl StageLabel) -> Option<&T> { + pub fn get_stage(&self, stage_label: impl StageLabel) -> Option<&T> { + let label = stage_label.as_label(); self.stages - .get(&label.as_label()) + .get(&label) .and_then(|stage| stage.downcast_ref::()) } @@ -326,9 +327,10 @@ impl Schedule { /// # /// let stage = schedule.get_stage_mut::("my_stage").unwrap(); /// ``` - pub fn get_stage_mut(&mut self, label: impl StageLabel) -> Option<&mut T> { + pub fn get_stage_mut(&mut self, stage_label: impl StageLabel) -> Option<&mut T> { + let label = stage_label.as_label(); self.stages - .get_mut(&label.as_label()) + .get_mut(&label) .and_then(|stage| stage.downcast_mut::()) }