Remove an outdated workaround for impl Trait (#5659)
# Objective Rust 1.63 resolved [an issue](https://github.com/rust-lang/rust/issues/83701) that prevents you from combining explicit generic arguments with `impl Trait` arguments. Now, we no longer need to use dynamic dispatch to work around this. ## Migration Guide The methods `Schedule::get_stage` and `get_stage_mut` now accept `impl StageLabel` instead of `&dyn StageLabel`. ### Before ```rust let stage = schedule.get_stage_mut::<SystemStage>(&MyLabel)?; ``` ### After ```rust let stage = schedule.get_stage_mut::<SystemStage>(MyLabel)?; ```
This commit is contained in:
parent
f9104b73a2
commit
3221e569e0
@ -211,9 +211,10 @@ impl Schedule {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let label = stage_label.as_label();
|
||||||
let stage = self
|
let stage = self
|
||||||
.get_stage_mut::<SystemStage>(&stage_label)
|
.get_stage_mut::<SystemStage>(label)
|
||||||
.unwrap_or_else(move || stage_not_found(&stage_label.as_label()));
|
.unwrap_or_else(move || stage_not_found(&label));
|
||||||
stage.add_system(system);
|
stage.add_system(system);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
@ -278,14 +279,12 @@ impl Schedule {
|
|||||||
/// Panics if `label` refers to a non-existing stage, or if it's not of type `T`.
|
/// Panics if `label` refers to a non-existing stage, or if it's not of type `T`.
|
||||||
pub fn stage<T: Stage, F: FnOnce(&mut T) -> &mut T>(
|
pub fn stage<T: Stage, F: FnOnce(&mut T) -> &mut T>(
|
||||||
&mut self,
|
&mut self,
|
||||||
label: impl StageLabel,
|
stage_label: impl StageLabel,
|
||||||
func: F,
|
func: F,
|
||||||
) -> &mut Self {
|
) -> &mut Self {
|
||||||
let stage = self.get_stage_mut::<T>(&label).unwrap_or_else(move || {
|
let label = stage_label.as_label();
|
||||||
panic!(
|
let stage = self.get_stage_mut::<T>(label).unwrap_or_else(move || {
|
||||||
"stage '{:?}' does not exist or is the wrong type",
|
panic!("stage '{label:?}' does not exist or is the wrong type",)
|
||||||
label.as_label()
|
|
||||||
)
|
|
||||||
});
|
});
|
||||||
func(stage);
|
func(stage);
|
||||||
self
|
self
|
||||||
@ -304,11 +303,12 @@ impl Schedule {
|
|||||||
/// # let mut schedule = Schedule::default();
|
/// # let mut schedule = Schedule::default();
|
||||||
/// # schedule.add_stage("my_stage", SystemStage::parallel());
|
/// # schedule.add_stage("my_stage", SystemStage::parallel());
|
||||||
/// #
|
/// #
|
||||||
/// let stage = schedule.get_stage::<SystemStage>(&"my_stage").unwrap();
|
/// let stage = schedule.get_stage::<SystemStage>("my_stage").unwrap();
|
||||||
/// ```
|
/// ```
|
||||||
pub fn get_stage<T: Stage>(&self, label: &dyn StageLabel) -> Option<&T> {
|
pub fn get_stage<T: Stage>(&self, stage_label: impl StageLabel) -> Option<&T> {
|
||||||
|
let label = stage_label.as_label();
|
||||||
self.stages
|
self.stages
|
||||||
.get(&label.as_label())
|
.get(&label)
|
||||||
.and_then(|stage| stage.downcast_ref::<T>())
|
.and_then(|stage| stage.downcast_ref::<T>())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -325,11 +325,12 @@ impl Schedule {
|
|||||||
/// # let mut schedule = Schedule::default();
|
/// # let mut schedule = Schedule::default();
|
||||||
/// # schedule.add_stage("my_stage", SystemStage::parallel());
|
/// # schedule.add_stage("my_stage", SystemStage::parallel());
|
||||||
/// #
|
/// #
|
||||||
/// let stage = schedule.get_stage_mut::<SystemStage>(&"my_stage").unwrap();
|
/// let stage = schedule.get_stage_mut::<SystemStage>("my_stage").unwrap();
|
||||||
/// ```
|
/// ```
|
||||||
pub fn get_stage_mut<T: Stage>(&mut self, label: &dyn StageLabel) -> Option<&mut T> {
|
pub fn get_stage_mut<T: Stage>(&mut self, stage_label: impl StageLabel) -> Option<&mut T> {
|
||||||
|
let label = stage_label.as_label();
|
||||||
self.stages
|
self.stages
|
||||||
.get_mut(&label.as_label())
|
.get_mut(&label)
|
||||||
.and_then(|stage| stage.downcast_mut::<T>())
|
.and_then(|stage| stage.downcast_mut::<T>())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -249,7 +249,7 @@ impl Plugin for RenderPlugin {
|
|||||||
// prepare
|
// prepare
|
||||||
let prepare = render_app
|
let prepare = render_app
|
||||||
.schedule
|
.schedule
|
||||||
.get_stage_mut::<SystemStage>(&RenderStage::Prepare)
|
.get_stage_mut::<SystemStage>(RenderStage::Prepare)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
prepare.run(&mut render_app.world);
|
prepare.run(&mut render_app.world);
|
||||||
}
|
}
|
||||||
@ -262,7 +262,7 @@ impl Plugin for RenderPlugin {
|
|||||||
// queue
|
// queue
|
||||||
let queue = render_app
|
let queue = render_app
|
||||||
.schedule
|
.schedule
|
||||||
.get_stage_mut::<SystemStage>(&RenderStage::Queue)
|
.get_stage_mut::<SystemStage>(RenderStage::Queue)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
queue.run(&mut render_app.world);
|
queue.run(&mut render_app.world);
|
||||||
}
|
}
|
||||||
@ -275,7 +275,7 @@ impl Plugin for RenderPlugin {
|
|||||||
// phase sort
|
// phase sort
|
||||||
let phase_sort = render_app
|
let phase_sort = render_app
|
||||||
.schedule
|
.schedule
|
||||||
.get_stage_mut::<SystemStage>(&RenderStage::PhaseSort)
|
.get_stage_mut::<SystemStage>(RenderStage::PhaseSort)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
phase_sort.run(&mut render_app.world);
|
phase_sort.run(&mut render_app.world);
|
||||||
}
|
}
|
||||||
@ -288,7 +288,7 @@ impl Plugin for RenderPlugin {
|
|||||||
// render
|
// render
|
||||||
let render = render_app
|
let render = render_app
|
||||||
.schedule
|
.schedule
|
||||||
.get_stage_mut::<SystemStage>(&RenderStage::Render)
|
.get_stage_mut::<SystemStage>(RenderStage::Render)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
render.run(&mut render_app.world);
|
render.run(&mut render_app.world);
|
||||||
}
|
}
|
||||||
@ -301,7 +301,7 @@ impl Plugin for RenderPlugin {
|
|||||||
// cleanup
|
// cleanup
|
||||||
let cleanup = render_app
|
let cleanup = render_app
|
||||||
.schedule
|
.schedule
|
||||||
.get_stage_mut::<SystemStage>(&RenderStage::Cleanup)
|
.get_stage_mut::<SystemStage>(RenderStage::Cleanup)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
cleanup.run(&mut render_app.world);
|
cleanup.run(&mut render_app.world);
|
||||||
}
|
}
|
||||||
@ -335,7 +335,7 @@ struct ScratchMainWorld(World);
|
|||||||
fn extract(app_world: &mut World, render_app: &mut App) {
|
fn extract(app_world: &mut World, render_app: &mut App) {
|
||||||
let extract = render_app
|
let extract = render_app
|
||||||
.schedule
|
.schedule
|
||||||
.get_stage_mut::<SystemStage>(&RenderStage::Extract)
|
.get_stage_mut::<SystemStage>(RenderStage::Extract)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
// temporarily add the app world to the render world as a resource
|
// temporarily add the app world to the render world as a resource
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user