Skip to content

Commit 76062ff

Browse files
committed
Remove uses of dynamic dispatch
1 parent a70b9c5 commit 76062ff

File tree

2 files changed

+16
-17
lines changed

2 files changed

+16
-17
lines changed

crates/bevy_ecs/src/schedule/mod.rs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -211,9 +211,10 @@ impl Schedule {
211211
)
212212
}
213213

214+
let stage_label = stage_label.as_label();
214215
let stage = self
215-
.get_stage_mut::<SystemStage>(&stage_label)
216-
.unwrap_or_else(move || stage_not_found(&stage_label.as_label()));
216+
.get_stage_mut::<SystemStage>(stage_label)
217+
.unwrap_or_else(move || stage_not_found(&stage_label));
217218
stage.add_system(system);
218219
self
219220
}
@@ -281,11 +282,9 @@ impl Schedule {
281282
label: impl StageLabel,
282283
func: F,
283284
) -> &mut Self {
284-
let stage = self.get_stage_mut::<T>(&label).unwrap_or_else(move || {
285-
panic!(
286-
"stage '{:?}' does not exist or is the wrong type",
287-
label.as_label()
288-
)
285+
let label = label.as_label();
286+
let stage = self.get_stage_mut::<T>(label).unwrap_or_else(move || {
287+
panic!("stage '{label:?}' does not exist or is the wrong type")
289288
});
290289
func(stage);
291290
self
@@ -304,9 +303,9 @@ impl Schedule {
304303
/// # let mut schedule = Schedule::default();
305304
/// # schedule.add_stage("my_stage", SystemStage::parallel());
306305
/// #
307-
/// let stage = schedule.get_stage::<SystemStage>(&"my_stage").unwrap();
306+
/// let stage = schedule.get_stage::<SystemStage>("my_stage").unwrap();
308307
/// ```
309-
pub fn get_stage<T: Stage>(&self, label: &dyn StageLabel) -> Option<&T> {
308+
pub fn get_stage<T: Stage>(&self, label: impl StageLabel) -> Option<&T> {
310309
self.stages
311310
.get(&label.as_label())
312311
.and_then(|stage| stage.downcast_ref::<T>())
@@ -325,9 +324,9 @@ impl Schedule {
325324
/// # let mut schedule = Schedule::default();
326325
/// # schedule.add_stage("my_stage", SystemStage::parallel());
327326
/// #
328-
/// let stage = schedule.get_stage_mut::<SystemStage>(&"my_stage").unwrap();
327+
/// let stage = schedule.get_stage_mut::<SystemStage>("my_stage").unwrap();
329328
/// ```
330-
pub fn get_stage_mut<T: Stage>(&mut self, label: &dyn StageLabel) -> Option<&mut T> {
329+
pub fn get_stage_mut<T: Stage>(&mut self, label: impl StageLabel) -> Option<&mut T> {
331330
self.stages
332331
.get_mut(&label.as_label())
333332
.and_then(|stage| stage.downcast_mut::<T>())

crates/bevy_render/src/lib.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ impl Plugin for RenderPlugin {
249249
// prepare
250250
let prepare = render_app
251251
.schedule
252-
.get_stage_mut::<SystemStage>(&RenderStage::Prepare)
252+
.get_stage_mut::<SystemStage>(RenderStage::Prepare)
253253
.unwrap();
254254
prepare.run(&mut render_app.world);
255255
}
@@ -262,7 +262,7 @@ impl Plugin for RenderPlugin {
262262
// queue
263263
let queue = render_app
264264
.schedule
265-
.get_stage_mut::<SystemStage>(&RenderStage::Queue)
265+
.get_stage_mut::<SystemStage>(RenderStage::Queue)
266266
.unwrap();
267267
queue.run(&mut render_app.world);
268268
}
@@ -275,7 +275,7 @@ impl Plugin for RenderPlugin {
275275
// phase sort
276276
let phase_sort = render_app
277277
.schedule
278-
.get_stage_mut::<SystemStage>(&RenderStage::PhaseSort)
278+
.get_stage_mut::<SystemStage>(RenderStage::PhaseSort)
279279
.unwrap();
280280
phase_sort.run(&mut render_app.world);
281281
}
@@ -288,7 +288,7 @@ impl Plugin for RenderPlugin {
288288
// render
289289
let render = render_app
290290
.schedule
291-
.get_stage_mut::<SystemStage>(&RenderStage::Render)
291+
.get_stage_mut::<SystemStage>(RenderStage::Render)
292292
.unwrap();
293293
render.run(&mut render_app.world);
294294
}
@@ -301,7 +301,7 @@ impl Plugin for RenderPlugin {
301301
// cleanup
302302
let cleanup = render_app
303303
.schedule
304-
.get_stage_mut::<SystemStage>(&RenderStage::Cleanup)
304+
.get_stage_mut::<SystemStage>(RenderStage::Cleanup)
305305
.unwrap();
306306
cleanup.run(&mut render_app.world);
307307
}
@@ -335,7 +335,7 @@ struct ScratchMainWorld(World);
335335
fn extract(app_world: &mut World, render_app: &mut App) {
336336
let extract = render_app
337337
.schedule
338-
.get_stage_mut::<SystemStage>(&RenderStage::Extract)
338+
.get_stage_mut::<SystemStage>(RenderStage::Extract)
339339
.unwrap();
340340

341341
// temporarily add the app world to the render world as a resource

0 commit comments

Comments
 (0)