Skip to content

Commit 4e9e78c

Browse files
Split BufferedEvent from Event (#20101)
# Objective > I think we should axe the shared `Event` trait entirely It doesn't serve any functional purpose, and I don't think it's useful pedagogically @alice-i-cecile on discord ## Solution - Remove `Event` as a supertrait of `BufferedEvent` - Remove any `Event` derives that were made unnecessary - Update release notes --------- Co-authored-by: SpecificProtagonist <[email protected]>
1 parent b47f6e8 commit 4e9e78c

File tree

50 files changed

+131
-138
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+131
-138
lines changed

benches/benches/bevy_ecs/events/iter.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use bevy_ecs::prelude::*;
22

3-
#[derive(Event, BufferedEvent)]
3+
#[derive(BufferedEvent)]
44
struct BenchEvent<const SIZE: usize>([u8; SIZE]);
55

66
pub struct Benchmark<const SIZE: usize>(Events<BenchEvent<SIZE>>);

benches/benches/bevy_ecs/events/write.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use bevy_ecs::prelude::*;
22

3-
#[derive(Event, BufferedEvent)]
3+
#[derive(BufferedEvent)]
44
struct BenchEvent<const SIZE: usize>([u8; SIZE]);
55

66
impl<const SIZE: usize> Default for BenchEvent<SIZE> {

crates/bevy_a11y/src/lib.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,7 @@ use accesskit::Node;
2626
use bevy_app::Plugin;
2727
use bevy_derive::{Deref, DerefMut};
2828
use bevy_ecs::{
29-
component::Component,
30-
event::{BufferedEvent, Event},
31-
resource::Resource,
32-
schedule::SystemSet,
29+
component::Component, event::BufferedEvent, resource::Resource, schedule::SystemSet,
3330
};
3431

3532
#[cfg(feature = "bevy_reflect")]
@@ -45,7 +42,7 @@ use serde::{Deserialize, Serialize};
4542
use bevy_reflect::{ReflectDeserialize, ReflectSerialize};
4643

4744
/// Wrapper struct for [`accesskit::ActionRequest`]. Required to allow it to be used as an `Event`.
48-
#[derive(Event, BufferedEvent, Deref, DerefMut)]
45+
#[derive(BufferedEvent, Deref, DerefMut)]
4946
#[cfg_attr(feature = "serialize", derive(Serialize, Deserialize))]
5047
pub struct ActionRequest(pub accesskit::ActionRequest);
5148

crates/bevy_app/src/app.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ impl App {
355355
/// # use bevy_app::prelude::*;
356356
/// # use bevy_ecs::prelude::*;
357357
/// #
358-
/// # #[derive(Event, BufferedEvent)]
358+
/// # #[derive(BufferedEvent)]
359359
/// # struct MyEvent;
360360
/// # let mut app = App::new();
361361
/// #
@@ -1417,7 +1417,7 @@ fn run_once(mut app: App) -> AppExit {
14171417
/// This type is roughly meant to map to a standard definition of a process exit code (0 means success, not 0 means error). Due to portability concerns
14181418
/// (see [`ExitCode`](https://doc.rust-lang.org/std/process/struct.ExitCode.html) and [`process::exit`](https://doc.rust-lang.org/std/process/fn.exit.html#))
14191419
/// we only allow error codes between 1 and [255](u8::MAX).
1420-
#[derive(Event, BufferedEvent, Debug, Clone, Default, PartialEq, Eq)]
1420+
#[derive(BufferedEvent, Debug, Clone, Default, PartialEq, Eq)]
14211421
pub enum AppExit {
14221422
/// [`App`] exited without any problems.
14231423
#[default]
@@ -1485,7 +1485,7 @@ mod tests {
14851485
change_detection::{DetectChanges, ResMut},
14861486
component::Component,
14871487
entity::Entity,
1488-
event::{BufferedEvent, Event, EventWriter, Events},
1488+
event::{BufferedEvent, EventWriter, Events},
14891489
lifecycle::RemovedComponents,
14901490
query::With,
14911491
resource::Resource,
@@ -1851,7 +1851,7 @@ mod tests {
18511851
}
18521852
#[test]
18531853
fn events_should_be_updated_once_per_update() {
1854-
#[derive(Event, BufferedEvent, Clone)]
1854+
#[derive(BufferedEvent, Clone)]
18551855
struct TestEvent;
18561856

18571857
let mut app = App::new();

crates/bevy_asset/src/event.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
use crate::{Asset, AssetId, AssetLoadError, AssetPath, UntypedAssetId};
2-
use bevy_ecs::event::{BufferedEvent, Event};
2+
use bevy_ecs::event::BufferedEvent;
33
use bevy_reflect::Reflect;
44
use core::fmt::Debug;
55

66
/// A [`BufferedEvent`] emitted when a specific [`Asset`] fails to load.
77
///
88
/// For an untyped equivalent, see [`UntypedAssetLoadFailedEvent`].
9-
#[derive(Event, BufferedEvent, Clone, Debug)]
9+
#[derive(BufferedEvent, Clone, Debug)]
1010
pub struct AssetLoadFailedEvent<A: Asset> {
1111
/// The stable identifier of the asset that failed to load.
1212
pub id: AssetId<A>,
@@ -24,7 +24,7 @@ impl<A: Asset> AssetLoadFailedEvent<A> {
2424
}
2525

2626
/// An untyped version of [`AssetLoadFailedEvent`].
27-
#[derive(Event, BufferedEvent, Clone, Debug)]
27+
#[derive(BufferedEvent, Clone, Debug)]
2828
pub struct UntypedAssetLoadFailedEvent {
2929
/// The stable identifier of the asset that failed to load.
3030
pub id: UntypedAssetId,
@@ -46,7 +46,7 @@ impl<A: Asset> From<&AssetLoadFailedEvent<A>> for UntypedAssetLoadFailedEvent {
4646

4747
/// [`BufferedEvent`]s that occur for a specific loaded [`Asset`], such as "value changed" events and "dependency" events.
4848
#[expect(missing_docs, reason = "Documenting the id fields is unhelpful.")]
49-
#[derive(Event, BufferedEvent, Reflect)]
49+
#[derive(BufferedEvent, Reflect)]
5050
pub enum AssetEvent<A: Asset> {
5151
/// Emitted whenever an [`Asset`] is added.
5252
Added { id: AssetId<A> },

crates/bevy_dev_tools/src/ci_testing/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ pub enum CiTestingEvent {
5252
}
5353

5454
/// A custom event that can be configured from a configuration file for CI testing.
55-
#[derive(Event, BufferedEvent)]
55+
#[derive(BufferedEvent)]
5656
pub struct CiTestingCustomEvent(pub String);
5757

5858
#[cfg(test)]

crates/bevy_ecs/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ They can be sent using the `EventWriter` system parameter and received with `Eve
285285
```rust
286286
use bevy_ecs::prelude::*;
287287

288-
#[derive(Event, BufferedEvent)]
288+
#[derive(BufferedEvent)]
289289
struct Message(String);
290290

291291
fn writer(mut writer: EventWriter<Message>) {

crates/bevy_ecs/examples/events.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ fn main() {
3737
}
3838

3939
// This is our event that we will send and receive in systems
40-
#[derive(Event, BufferedEvent)]
40+
#[derive(BufferedEvent)]
4141
struct MyEvent {
4242
pub message: String,
4343
pub random_value: f32,

crates/bevy_ecs/src/change_detection.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ pub trait DetectChangesMut: DetectChanges {
230230
/// #[derive(Resource, PartialEq, Eq)]
231231
/// pub struct Score(u32);
232232
///
233-
/// #[derive(Event, BufferedEvent, PartialEq, Eq)]
233+
/// #[derive(BufferedEvent, PartialEq, Eq)]
234234
/// pub struct ScoreChanged {
235235
/// current: u32,
236236
/// previous: u32,

crates/bevy_ecs/src/event/base.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ pub trait EntityEvent: Event {
259259
const AUTO_PROPAGATE: bool = false;
260260
}
261261

262-
/// A buffered [`Event`] for pull-based event handling.
262+
/// A buffered event for pull-based event handling.
263263
///
264264
/// Buffered events can be written with [`EventWriter`] and read using the [`EventReader`] system parameter.
265265
/// These events are stored in the [`Events<E>`] resource, and require periodically polling the world for new events,
@@ -286,7 +286,7 @@ pub trait EntityEvent: Event {
286286
/// ```
287287
/// # use bevy_ecs::prelude::*;
288288
/// #
289-
/// #[derive(Event, BufferedEvent)]
289+
/// #[derive(BufferedEvent)]
290290
/// struct Message(String);
291291
/// ```
292292
///
@@ -295,7 +295,7 @@ pub trait EntityEvent: Event {
295295
/// ```
296296
/// # use bevy_ecs::prelude::*;
297297
/// #
298-
/// # #[derive(Event, BufferedEvent)]
298+
/// # #[derive(BufferedEvent)]
299299
/// # struct Message(String);
300300
/// #
301301
/// fn write_hello(mut writer: EventWriter<Message>) {
@@ -308,7 +308,7 @@ pub trait EntityEvent: Event {
308308
/// ```
309309
/// # use bevy_ecs::prelude::*;
310310
/// #
311-
/// # #[derive(Event, BufferedEvent)]
311+
/// # #[derive(BufferedEvent)]
312312
/// # struct Message(String);
313313
/// #
314314
/// fn read_messages(mut reader: EventReader<Message>) {
@@ -327,9 +327,9 @@ pub trait EntityEvent: Event {
327327
#[diagnostic::on_unimplemented(
328328
message = "`{Self}` is not an `BufferedEvent`",
329329
label = "invalid `BufferedEvent`",
330-
note = "consider annotating `{Self}` with `#[derive(Event, BufferedEvent)]`"
330+
note = "consider annotating `{Self}` with `#[derive(BufferedEvent)]`"
331331
)]
332-
pub trait BufferedEvent: Event {}
332+
pub trait BufferedEvent: Send + Sync + 'static {}
333333

334334
/// An internal type that implements [`Component`] for a given [`Event`] type.
335335
///

0 commit comments

Comments
 (0)