Add Default for all schedule labels (#18731)

# Objective

In `bevy_enhanced_input`, I'm trying to associate `Actions` with a
schedule. I can do this via an associated type on a trait, but there's
no way to construct the associated label except by requiring a `Default`
implementation. However, Bevy labels don't implement `Default`.

## Solution

Add `Default` to all built-in labels. I think it should be useful in
general.
This commit is contained in:
Hennadii Chernyshchyk 2025-04-06 19:44:33 +03:00 committed by GitHub
parent 5dcfa52297
commit d82c359a5a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 24 additions and 24 deletions

View File

@ -52,31 +52,31 @@ use bevy_ecs::{
/// [`RenderPlugin`]: https://docs.rs/bevy/latest/bevy/render/struct.RenderPlugin.html /// [`RenderPlugin`]: https://docs.rs/bevy/latest/bevy/render/struct.RenderPlugin.html
/// [`PipelinedRenderingPlugin`]: https://docs.rs/bevy/latest/bevy/render/pipelined_rendering/struct.PipelinedRenderingPlugin.html /// [`PipelinedRenderingPlugin`]: https://docs.rs/bevy/latest/bevy/render/pipelined_rendering/struct.PipelinedRenderingPlugin.html
/// [`SubApp`]: crate::SubApp /// [`SubApp`]: crate::SubApp
#[derive(ScheduleLabel, Clone, Debug, PartialEq, Eq, Hash)] #[derive(ScheduleLabel, Clone, Debug, PartialEq, Eq, Hash, Default)]
pub struct Main; pub struct Main;
/// The schedule that runs before [`Startup`]. /// The schedule that runs before [`Startup`].
/// ///
/// See the [`Main`] schedule for some details about how schedules are run. /// See the [`Main`] schedule for some details about how schedules are run.
#[derive(ScheduleLabel, Clone, Debug, PartialEq, Eq, Hash)] #[derive(ScheduleLabel, Clone, Debug, PartialEq, Eq, Hash, Default)]
pub struct PreStartup; pub struct PreStartup;
/// The schedule that runs once when the app starts. /// The schedule that runs once when the app starts.
/// ///
/// See the [`Main`] schedule for some details about how schedules are run. /// See the [`Main`] schedule for some details about how schedules are run.
#[derive(ScheduleLabel, Clone, Debug, PartialEq, Eq, Hash)] #[derive(ScheduleLabel, Clone, Debug, PartialEq, Eq, Hash, Default)]
pub struct Startup; pub struct Startup;
/// The schedule that runs once after [`Startup`]. /// The schedule that runs once after [`Startup`].
/// ///
/// See the [`Main`] schedule for some details about how schedules are run. /// See the [`Main`] schedule for some details about how schedules are run.
#[derive(ScheduleLabel, Clone, Debug, PartialEq, Eq, Hash)] #[derive(ScheduleLabel, Clone, Debug, PartialEq, Eq, Hash, Default)]
pub struct PostStartup; pub struct PostStartup;
/// Runs first in the schedule. /// Runs first in the schedule.
/// ///
/// See the [`Main`] schedule for some details about how schedules are run. /// See the [`Main`] schedule for some details about how schedules are run.
#[derive(ScheduleLabel, Clone, Debug, PartialEq, Eq, Hash)] #[derive(ScheduleLabel, Clone, Debug, PartialEq, Eq, Hash, Default)]
pub struct First; pub struct First;
/// The schedule that contains logic that must run before [`Update`]. For example, a system that reads raw keyboard /// The schedule that contains logic that must run before [`Update`]. For example, a system that reads raw keyboard
@ -87,7 +87,7 @@ pub struct First;
/// [`PreUpdate`] abstracts out "pre work implementation details". /// [`PreUpdate`] abstracts out "pre work implementation details".
/// ///
/// See the [`Main`] schedule for some details about how schedules are run. /// See the [`Main`] schedule for some details about how schedules are run.
#[derive(ScheduleLabel, Clone, Debug, PartialEq, Eq, Hash)] #[derive(ScheduleLabel, Clone, Debug, PartialEq, Eq, Hash, Default)]
pub struct PreUpdate; pub struct PreUpdate;
/// Runs the [`FixedMain`] schedule in a loop according until all relevant elapsed time has been "consumed". /// Runs the [`FixedMain`] schedule in a loop according until all relevant elapsed time has been "consumed".
@ -99,21 +99,21 @@ pub struct PreUpdate;
/// [`RunFixedMainLoop`] will *not* be parallelized between each other. /// [`RunFixedMainLoop`] will *not* be parallelized between each other.
/// ///
/// See the [`Main`] schedule for some details about how schedules are run. /// See the [`Main`] schedule for some details about how schedules are run.
#[derive(ScheduleLabel, Clone, Debug, PartialEq, Eq, Hash)] #[derive(ScheduleLabel, Clone, Debug, PartialEq, Eq, Hash, Default)]
pub struct RunFixedMainLoop; pub struct RunFixedMainLoop;
/// Runs first in the [`FixedMain`] schedule. /// Runs first in the [`FixedMain`] schedule.
/// ///
/// See the [`FixedMain`] schedule for details on how fixed updates work. /// See the [`FixedMain`] schedule for details on how fixed updates work.
/// See the [`Main`] schedule for some details about how schedules are run. /// See the [`Main`] schedule for some details about how schedules are run.
#[derive(ScheduleLabel, Clone, Debug, PartialEq, Eq, Hash)] #[derive(ScheduleLabel, Clone, Debug, PartialEq, Eq, Hash, Default)]
pub struct FixedFirst; pub struct FixedFirst;
/// The schedule that contains logic that must run before [`FixedUpdate`]. /// The schedule that contains logic that must run before [`FixedUpdate`].
/// ///
/// See the [`FixedMain`] schedule for details on how fixed updates work. /// See the [`FixedMain`] schedule for details on how fixed updates work.
/// See the [`Main`] schedule for some details about how schedules are run. /// See the [`Main`] schedule for some details about how schedules are run.
#[derive(ScheduleLabel, Clone, Debug, PartialEq, Eq, Hash)] #[derive(ScheduleLabel, Clone, Debug, PartialEq, Eq, Hash, Default)]
pub struct FixedPreUpdate; pub struct FixedPreUpdate;
/// The schedule that contains most gameplay logic, which runs at a fixed rate rather than every render frame. /// The schedule that contains most gameplay logic, which runs at a fixed rate rather than every render frame.
@ -128,7 +128,7 @@ pub struct FixedPreUpdate;
/// See the [`Update`] schedule for examples of systems that *should not* use this schedule. /// See the [`Update`] schedule for examples of systems that *should not* use this schedule.
/// See the [`FixedMain`] schedule for details on how fixed updates work. /// See the [`FixedMain`] schedule for details on how fixed updates work.
/// See the [`Main`] schedule for some details about how schedules are run. /// See the [`Main`] schedule for some details about how schedules are run.
#[derive(ScheduleLabel, Clone, Debug, PartialEq, Eq, Hash)] #[derive(ScheduleLabel, Clone, Debug, PartialEq, Eq, Hash, Default)]
pub struct FixedUpdate; pub struct FixedUpdate;
/// The schedule that runs after the [`FixedUpdate`] schedule, for reacting /// The schedule that runs after the [`FixedUpdate`] schedule, for reacting
@ -136,14 +136,14 @@ pub struct FixedUpdate;
/// ///
/// See the [`FixedMain`] schedule for details on how fixed updates work. /// See the [`FixedMain`] schedule for details on how fixed updates work.
/// See the [`Main`] schedule for some details about how schedules are run. /// See the [`Main`] schedule for some details about how schedules are run.
#[derive(ScheduleLabel, Clone, Debug, PartialEq, Eq, Hash)] #[derive(ScheduleLabel, Clone, Debug, PartialEq, Eq, Hash, Default)]
pub struct FixedPostUpdate; pub struct FixedPostUpdate;
/// The schedule that runs last in [`FixedMain`] /// The schedule that runs last in [`FixedMain`]
/// ///
/// See the [`FixedMain`] schedule for details on how fixed updates work. /// See the [`FixedMain`] schedule for details on how fixed updates work.
/// See the [`Main`] schedule for some details about how schedules are run. /// See the [`Main`] schedule for some details about how schedules are run.
#[derive(ScheduleLabel, Clone, Debug, PartialEq, Eq, Hash)] #[derive(ScheduleLabel, Clone, Debug, PartialEq, Eq, Hash, Default)]
pub struct FixedLast; pub struct FixedLast;
/// The schedule that contains systems which only run after a fixed period of time has elapsed. /// The schedule that contains systems which only run after a fixed period of time has elapsed.
@ -155,7 +155,7 @@ pub struct FixedLast;
/// See [this example](https://github.com/bevyengine/bevy/blob/latest/examples/time/time.rs). /// See [this example](https://github.com/bevyengine/bevy/blob/latest/examples/time/time.rs).
/// ///
/// See the [`Main`] schedule for some details about how schedules are run. /// See the [`Main`] schedule for some details about how schedules are run.
#[derive(ScheduleLabel, Clone, Debug, PartialEq, Eq, Hash)] #[derive(ScheduleLabel, Clone, Debug, PartialEq, Eq, Hash, Default)]
pub struct FixedMain; pub struct FixedMain;
/// The schedule that contains any app logic that must run once per render frame. /// The schedule that contains any app logic that must run once per render frame.
@ -168,13 +168,13 @@ pub struct FixedMain;
/// ///
/// See the [`FixedUpdate`] schedule for examples of systems that *should not* use this schedule. /// See the [`FixedUpdate`] schedule for examples of systems that *should not* use this schedule.
/// See the [`Main`] schedule for some details about how schedules are run. /// See the [`Main`] schedule for some details about how schedules are run.
#[derive(ScheduleLabel, Clone, Debug, PartialEq, Eq, Hash)] #[derive(ScheduleLabel, Clone, Debug, PartialEq, Eq, Hash, Default)]
pub struct Update; pub struct Update;
/// The schedule that contains scene spawning. /// The schedule that contains scene spawning.
/// ///
/// See the [`Main`] schedule for some details about how schedules are run. /// See the [`Main`] schedule for some details about how schedules are run.
#[derive(ScheduleLabel, Clone, Debug, PartialEq, Eq, Hash)] #[derive(ScheduleLabel, Clone, Debug, PartialEq, Eq, Hash, Default)]
pub struct SpawnScene; pub struct SpawnScene;
/// The schedule that contains logic that must run after [`Update`]. For example, synchronizing "local transforms" in a hierarchy /// The schedule that contains logic that must run after [`Update`]. For example, synchronizing "local transforms" in a hierarchy
@ -185,13 +185,13 @@ pub struct SpawnScene;
/// [`PostUpdate`] abstracts out "implementation details" from users defining systems in [`Update`]. /// [`PostUpdate`] abstracts out "implementation details" from users defining systems in [`Update`].
/// ///
/// See the [`Main`] schedule for some details about how schedules are run. /// See the [`Main`] schedule for some details about how schedules are run.
#[derive(ScheduleLabel, Clone, Debug, PartialEq, Eq, Hash)] #[derive(ScheduleLabel, Clone, Debug, PartialEq, Eq, Hash, Default)]
pub struct PostUpdate; pub struct PostUpdate;
/// Runs last in the schedule. /// Runs last in the schedule.
/// ///
/// See the [`Main`] schedule for some details about how schedules are run. /// See the [`Main`] schedule for some details about how schedules are run.
#[derive(ScheduleLabel, Clone, Debug, PartialEq, Eq, Hash)] #[derive(ScheduleLabel, Clone, Debug, PartialEq, Eq, Hash, Default)]
pub struct Last; pub struct Last;
/// Animation system set. This exists in [`PostUpdate`]. /// Animation system set. This exists in [`PostUpdate`].

View File

@ -558,7 +558,7 @@ impl Plugin for RemotePlugin {
} }
/// Schedule that contains all systems to process Bevy Remote Protocol requests /// Schedule that contains all systems to process Bevy Remote Protocol requests
#[derive(ScheduleLabel, Clone, Debug, PartialEq, Eq, Hash)] #[derive(ScheduleLabel, Clone, Debug, PartialEq, Eq, Hash, Default)]
pub struct RemoteLast; pub struct RemoteLast;
/// The systems sets of the [`RemoteLast`] schedule. /// The systems sets of the [`RemoteLast`] schedule.

View File

@ -190,7 +190,7 @@ pub enum RenderSet {
} }
/// The main render schedule. /// The main render schedule.
#[derive(ScheduleLabel, Debug, Hash, PartialEq, Eq, Clone)] #[derive(ScheduleLabel, Debug, Hash, PartialEq, Eq, Clone, Default)]
pub struct Render; pub struct Render;
impl Render { impl Render {
@ -246,7 +246,7 @@ impl Render {
/// ///
/// This schedule is run on the main world, but its buffers are not applied /// This schedule is run on the main world, but its buffers are not applied
/// until it is returned to the render world. /// until it is returned to the render world.
#[derive(ScheduleLabel, PartialEq, Eq, Debug, Clone, Hash)] #[derive(ScheduleLabel, PartialEq, Eq, Debug, Clone, Hash, Default)]
pub struct ExtractSchedule; pub struct ExtractSchedule;
/// The simulation [`World`] of the application, stored as a resource. /// The simulation [`World`] of the application, stored as a resource.

View File

@ -12,13 +12,13 @@ use super::{resources::State, states::States};
/// The label of a [`Schedule`] that **only** runs whenever [`State<S>`] enters the provided state. /// The label of a [`Schedule`] that **only** runs whenever [`State<S>`] enters the provided state.
/// ///
/// This schedule ignores identity transitions. /// This schedule ignores identity transitions.
#[derive(ScheduleLabel, Clone, Debug, PartialEq, Eq, Hash)] #[derive(ScheduleLabel, Clone, Debug, PartialEq, Eq, Hash, Default)]
pub struct OnEnter<S: States>(pub S); pub struct OnEnter<S: States>(pub S);
/// The label of a [`Schedule`] that **only** runs whenever [`State<S>`] exits the provided state. /// The label of a [`Schedule`] that **only** runs whenever [`State<S>`] exits the provided state.
/// ///
/// This schedule ignores identity transitions. /// This schedule ignores identity transitions.
#[derive(ScheduleLabel, Clone, Debug, PartialEq, Eq, Hash)] #[derive(ScheduleLabel, Clone, Debug, PartialEq, Eq, Hash, Default)]
pub struct OnExit<S: States>(pub S); pub struct OnExit<S: States>(pub S);
/// The label of a [`Schedule`] that **only** runs whenever [`State<S>`] /// The label of a [`Schedule`] that **only** runs whenever [`State<S>`]
@ -27,7 +27,7 @@ pub struct OnExit<S: States>(pub S);
/// Systems added to this schedule are always ran *after* [`OnExit`], and *before* [`OnEnter`]. /// Systems added to this schedule are always ran *after* [`OnExit`], and *before* [`OnEnter`].
/// ///
/// This schedule will run on identity transitions. /// This schedule will run on identity transitions.
#[derive(ScheduleLabel, Clone, Debug, PartialEq, Eq, Hash)] #[derive(ScheduleLabel, Clone, Debug, PartialEq, Eq, Hash, Default)]
pub struct OnTransition<S: States> { pub struct OnTransition<S: States> {
/// The state being exited. /// The state being exited.
pub exited: S, pub exited: S,
@ -52,7 +52,7 @@ pub struct OnTransition<S: States> {
/// ///
/// [`PreStartup`]: https://docs.rs/bevy/latest/bevy/prelude/struct.PreStartup.html /// [`PreStartup`]: https://docs.rs/bevy/latest/bevy/prelude/struct.PreStartup.html
/// [`PreUpdate`]: https://docs.rs/bevy/latest/bevy/prelude/struct.PreUpdate.html /// [`PreUpdate`]: https://docs.rs/bevy/latest/bevy/prelude/struct.PreUpdate.html
#[derive(ScheduleLabel, Clone, Debug, PartialEq, Eq, Hash)] #[derive(ScheduleLabel, Clone, Debug, PartialEq, Eq, Hash, Default)]
pub struct StateTransition; pub struct StateTransition;
/// Event sent when any state transition of `S` happens. /// Event sent when any state transition of `S` happens.