Skip to content

Commit d82c359

Browse files
authored
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.
1 parent 5dcfa52 commit d82c359

File tree

4 files changed

+24
-24
lines changed

4 files changed

+24
-24
lines changed

crates/bevy_app/src/main_schedule.rs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -52,31 +52,31 @@ use bevy_ecs::{
5252
/// [`RenderPlugin`]: https://docs.rs/bevy/latest/bevy/render/struct.RenderPlugin.html
5353
/// [`PipelinedRenderingPlugin`]: https://docs.rs/bevy/latest/bevy/render/pipelined_rendering/struct.PipelinedRenderingPlugin.html
5454
/// [`SubApp`]: crate::SubApp
55-
#[derive(ScheduleLabel, Clone, Debug, PartialEq, Eq, Hash)]
55+
#[derive(ScheduleLabel, Clone, Debug, PartialEq, Eq, Hash, Default)]
5656
pub struct Main;
5757

5858
/// The schedule that runs before [`Startup`].
5959
///
6060
/// See the [`Main`] schedule for some details about how schedules are run.
61-
#[derive(ScheduleLabel, Clone, Debug, PartialEq, Eq, Hash)]
61+
#[derive(ScheduleLabel, Clone, Debug, PartialEq, Eq, Hash, Default)]
6262
pub struct PreStartup;
6363

6464
/// The schedule that runs once when the app starts.
6565
///
6666
/// See the [`Main`] schedule for some details about how schedules are run.
67-
#[derive(ScheduleLabel, Clone, Debug, PartialEq, Eq, Hash)]
67+
#[derive(ScheduleLabel, Clone, Debug, PartialEq, Eq, Hash, Default)]
6868
pub struct Startup;
6969

7070
/// The schedule that runs once after [`Startup`].
7171
///
7272
/// See the [`Main`] schedule for some details about how schedules are run.
73-
#[derive(ScheduleLabel, Clone, Debug, PartialEq, Eq, Hash)]
73+
#[derive(ScheduleLabel, Clone, Debug, PartialEq, Eq, Hash, Default)]
7474
pub struct PostStartup;
7575

7676
/// Runs first in the schedule.
7777
///
7878
/// See the [`Main`] schedule for some details about how schedules are run.
79-
#[derive(ScheduleLabel, Clone, Debug, PartialEq, Eq, Hash)]
79+
#[derive(ScheduleLabel, Clone, Debug, PartialEq, Eq, Hash, Default)]
8080
pub struct First;
8181

8282
/// 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;
8787
/// [`PreUpdate`] abstracts out "pre work implementation details".
8888
///
8989
/// See the [`Main`] schedule for some details about how schedules are run.
90-
#[derive(ScheduleLabel, Clone, Debug, PartialEq, Eq, Hash)]
90+
#[derive(ScheduleLabel, Clone, Debug, PartialEq, Eq, Hash, Default)]
9191
pub struct PreUpdate;
9292

9393
/// Runs the [`FixedMain`] schedule in a loop according until all relevant elapsed time has been "consumed".
@@ -99,21 +99,21 @@ pub struct PreUpdate;
9999
/// [`RunFixedMainLoop`] will *not* be parallelized between each other.
100100
///
101101
/// See the [`Main`] schedule for some details about how schedules are run.
102-
#[derive(ScheduleLabel, Clone, Debug, PartialEq, Eq, Hash)]
102+
#[derive(ScheduleLabel, Clone, Debug, PartialEq, Eq, Hash, Default)]
103103
pub struct RunFixedMainLoop;
104104

105105
/// Runs first in the [`FixedMain`] schedule.
106106
///
107107
/// See the [`FixedMain`] schedule for details on how fixed updates work.
108108
/// See the [`Main`] schedule for some details about how schedules are run.
109-
#[derive(ScheduleLabel, Clone, Debug, PartialEq, Eq, Hash)]
109+
#[derive(ScheduleLabel, Clone, Debug, PartialEq, Eq, Hash, Default)]
110110
pub struct FixedFirst;
111111

112112
/// The schedule that contains logic that must run before [`FixedUpdate`].
113113
///
114114
/// See the [`FixedMain`] schedule for details on how fixed updates work.
115115
/// See the [`Main`] schedule for some details about how schedules are run.
116-
#[derive(ScheduleLabel, Clone, Debug, PartialEq, Eq, Hash)]
116+
#[derive(ScheduleLabel, Clone, Debug, PartialEq, Eq, Hash, Default)]
117117
pub struct FixedPreUpdate;
118118

119119
/// The schedule that contains most gameplay logic, which runs at a fixed rate rather than every render frame.
@@ -128,22 +128,22 @@ pub struct FixedPreUpdate;
128128
/// See the [`Update`] schedule for examples of systems that *should not* use this schedule.
129129
/// See the [`FixedMain`] schedule for details on how fixed updates work.
130130
/// See the [`Main`] schedule for some details about how schedules are run.
131-
#[derive(ScheduleLabel, Clone, Debug, PartialEq, Eq, Hash)]
131+
#[derive(ScheduleLabel, Clone, Debug, PartialEq, Eq, Hash, Default)]
132132
pub struct FixedUpdate;
133133

134134
/// The schedule that runs after the [`FixedUpdate`] schedule, for reacting
135135
/// to changes made in the main update logic.
136136
///
137137
/// See the [`FixedMain`] schedule for details on how fixed updates work.
138138
/// See the [`Main`] schedule for some details about how schedules are run.
139-
#[derive(ScheduleLabel, Clone, Debug, PartialEq, Eq, Hash)]
139+
#[derive(ScheduleLabel, Clone, Debug, PartialEq, Eq, Hash, Default)]
140140
pub struct FixedPostUpdate;
141141

142142
/// The schedule that runs last in [`FixedMain`]
143143
///
144144
/// See the [`FixedMain`] schedule for details on how fixed updates work.
145145
/// See the [`Main`] schedule for some details about how schedules are run.
146-
#[derive(ScheduleLabel, Clone, Debug, PartialEq, Eq, Hash)]
146+
#[derive(ScheduleLabel, Clone, Debug, PartialEq, Eq, Hash, Default)]
147147
pub struct FixedLast;
148148

149149
/// The schedule that contains systems which only run after a fixed period of time has elapsed.
@@ -155,7 +155,7 @@ pub struct FixedLast;
155155
/// See [this example](https://github.com/bevyengine/bevy/blob/latest/examples/time/time.rs).
156156
///
157157
/// See the [`Main`] schedule for some details about how schedules are run.
158-
#[derive(ScheduleLabel, Clone, Debug, PartialEq, Eq, Hash)]
158+
#[derive(ScheduleLabel, Clone, Debug, PartialEq, Eq, Hash, Default)]
159159
pub struct FixedMain;
160160

161161
/// The schedule that contains any app logic that must run once per render frame.
@@ -168,13 +168,13 @@ pub struct FixedMain;
168168
///
169169
/// See the [`FixedUpdate`] schedule for examples of systems that *should not* use this schedule.
170170
/// See the [`Main`] schedule for some details about how schedules are run.
171-
#[derive(ScheduleLabel, Clone, Debug, PartialEq, Eq, Hash)]
171+
#[derive(ScheduleLabel, Clone, Debug, PartialEq, Eq, Hash, Default)]
172172
pub struct Update;
173173

174174
/// The schedule that contains scene spawning.
175175
///
176176
/// See the [`Main`] schedule for some details about how schedules are run.
177-
#[derive(ScheduleLabel, Clone, Debug, PartialEq, Eq, Hash)]
177+
#[derive(ScheduleLabel, Clone, Debug, PartialEq, Eq, Hash, Default)]
178178
pub struct SpawnScene;
179179

180180
/// 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;
185185
/// [`PostUpdate`] abstracts out "implementation details" from users defining systems in [`Update`].
186186
///
187187
/// See the [`Main`] schedule for some details about how schedules are run.
188-
#[derive(ScheduleLabel, Clone, Debug, PartialEq, Eq, Hash)]
188+
#[derive(ScheduleLabel, Clone, Debug, PartialEq, Eq, Hash, Default)]
189189
pub struct PostUpdate;
190190

191191
/// Runs last in the schedule.
192192
///
193193
/// See the [`Main`] schedule for some details about how schedules are run.
194-
#[derive(ScheduleLabel, Clone, Debug, PartialEq, Eq, Hash)]
194+
#[derive(ScheduleLabel, Clone, Debug, PartialEq, Eq, Hash, Default)]
195195
pub struct Last;
196196

197197
/// Animation system set. This exists in [`PostUpdate`].

crates/bevy_remote/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,7 @@ impl Plugin for RemotePlugin {
558558
}
559559

560560
/// Schedule that contains all systems to process Bevy Remote Protocol requests
561-
#[derive(ScheduleLabel, Clone, Debug, PartialEq, Eq, Hash)]
561+
#[derive(ScheduleLabel, Clone, Debug, PartialEq, Eq, Hash, Default)]
562562
pub struct RemoteLast;
563563

564564
/// The systems sets of the [`RemoteLast`] schedule.

crates/bevy_render/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ pub enum RenderSet {
190190
}
191191

192192
/// The main render schedule.
193-
#[derive(ScheduleLabel, Debug, Hash, PartialEq, Eq, Clone)]
193+
#[derive(ScheduleLabel, Debug, Hash, PartialEq, Eq, Clone, Default)]
194194
pub struct Render;
195195

196196
impl Render {
@@ -246,7 +246,7 @@ impl Render {
246246
///
247247
/// This schedule is run on the main world, but its buffers are not applied
248248
/// until it is returned to the render world.
249-
#[derive(ScheduleLabel, PartialEq, Eq, Debug, Clone, Hash)]
249+
#[derive(ScheduleLabel, PartialEq, Eq, Debug, Clone, Hash, Default)]
250250
pub struct ExtractSchedule;
251251

252252
/// The simulation [`World`] of the application, stored as a resource.

crates/bevy_state/src/state/transitions.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ use super::{resources::State, states::States};
1212
/// The label of a [`Schedule`] that **only** runs whenever [`State<S>`] enters the provided state.
1313
///
1414
/// This schedule ignores identity transitions.
15-
#[derive(ScheduleLabel, Clone, Debug, PartialEq, Eq, Hash)]
15+
#[derive(ScheduleLabel, Clone, Debug, PartialEq, Eq, Hash, Default)]
1616
pub struct OnEnter<S: States>(pub S);
1717

1818
/// The label of a [`Schedule`] that **only** runs whenever [`State<S>`] exits the provided state.
1919
///
2020
/// This schedule ignores identity transitions.
21-
#[derive(ScheduleLabel, Clone, Debug, PartialEq, Eq, Hash)]
21+
#[derive(ScheduleLabel, Clone, Debug, PartialEq, Eq, Hash, Default)]
2222
pub struct OnExit<S: States>(pub S);
2323

2424
/// The label of a [`Schedule`] that **only** runs whenever [`State<S>`]
@@ -27,7 +27,7 @@ pub struct OnExit<S: States>(pub S);
2727
/// Systems added to this schedule are always ran *after* [`OnExit`], and *before* [`OnEnter`].
2828
///
2929
/// This schedule will run on identity transitions.
30-
#[derive(ScheduleLabel, Clone, Debug, PartialEq, Eq, Hash)]
30+
#[derive(ScheduleLabel, Clone, Debug, PartialEq, Eq, Hash, Default)]
3131
pub struct OnTransition<S: States> {
3232
/// The state being exited.
3333
pub exited: S,
@@ -52,7 +52,7 @@ pub struct OnTransition<S: States> {
5252
///
5353
/// [`PreStartup`]: https://docs.rs/bevy/latest/bevy/prelude/struct.PreStartup.html
5454
/// [`PreUpdate`]: https://docs.rs/bevy/latest/bevy/prelude/struct.PreUpdate.html
55-
#[derive(ScheduleLabel, Clone, Debug, PartialEq, Eq, Hash)]
55+
#[derive(ScheduleLabel, Clone, Debug, PartialEq, Eq, Hash, Default)]
5656
pub struct StateTransition;
5757

5858
/// Event sent when any state transition of `S` happens.

0 commit comments

Comments
 (0)