diff --git a/crates/bevy_ecs/src/event.rs b/crates/bevy_ecs/src/event.rs index 7426c59abc9b6..5b5aa3cc5fcfc 100644 --- a/crates/bevy_ecs/src/event.rs +++ b/crates/bevy_ecs/src/event.rs @@ -183,19 +183,31 @@ impl DerefMut for EventSequence { } /// [Label](SystemLabel) for a [`System`](crate::system::System) that reads events of type `E`. -#[derive(SystemLabel)] -#[system_label(ignore_fields)] -pub struct ReadSystem(PhantomData); +pub struct Reads(()); + +impl Reads { + /// Returns a [`SystemLabel`] for a system that reads events of type `E`. + pub fn from() -> impl SystemLabel { + struct ReadSystem(PhantomData); + + impl SystemLabel for ReadSystem { + fn as_str(&self) -> &'static str { + // FIXME: using `type_name` for equality is kinda sketchy, + // but we won't need it after https://github.com/bevyengine/bevy/pull/5377. + // This *should* be fine for the time being though, as the behavior + // of `type_name` is only subject to change between compiler versions, + // so the only place it might be able to cause issues is with dynamic plugins. + std::any::type_name::() + } + } -impl Default for ReadSystem { - fn default() -> Self { - Self(PhantomData) + ReadSystem::(PhantomData) } } /// Reads events of type `T` in order and tracks which events have already been read. #[derive(SystemParam)] -#[system_param(label = ReadSystem::::default())] +#[system_param(label = Reads::from::())] pub struct EventReader<'w, 's, E: Event> { reader: Local<'s, ManualEventReader>, events: Res<'w, Events>, @@ -263,14 +275,21 @@ impl<'w, 's, E: Event> EventReader<'w, 's, E> { } } -/// [Label](SystemLabel) for a [`System`](crate::system::System) that writes events of type `E`. -#[derive(SystemLabel)] -#[system_label(ignore_fields)] -pub struct WriteSystem(PhantomData); +/// [Label](SystemLabel) for a [`System`](crate::system::System) that can write events of type `E`. +pub struct Writes(()); -impl Default for WriteSystem { - fn default() -> Self { - Self(PhantomData) +impl Writes { + /// Returns a [`SystemLabel`] for a system that can write events of type `E`. + pub fn to() -> impl SystemLabel { + struct WriteSystem(PhantomData); + + impl SystemLabel for WriteSystem { + fn as_str(&self) -> &'static str { + std::any::type_name::() + } + } + + WriteSystem::(PhantomData) } } @@ -318,7 +337,7 @@ impl Default for WriteSystem { /// ``` /// Note that this is considered *non-idiomatic*, and should only be used when `EventWriter` will not work. #[derive(SystemParam)] -#[system_param(label = WriteSystem::::default())] +#[system_param(label = Writes::to::())] pub struct EventWriter<'w, 's, E: Event> { events: ResMut<'w, Events>, #[system_param(ignore)]