@@ -183,19 +183,31 @@ impl<E: Event> DerefMut for EventSequence<E> {
183
183
}
184
184
185
185
/// [Label](SystemLabel) for a [`System`](crate::system::System) that reads events of type `E`.
186
- #[ derive( SystemLabel ) ]
187
- #[ system_label( ignore_fields) ]
188
- pub struct ReadSystem < E : Event > ( PhantomData < E > ) ;
186
+ pub struct Reads ( ( ) ) ;
187
+
188
+ impl Reads {
189
+ /// Returns a [`SystemLabel`] for a system that reads events of type `E`.
190
+ pub fn from < E : Event > ( ) -> impl SystemLabel {
191
+ struct ReadSystem < E > ( PhantomData < E > ) ;
192
+
193
+ impl < E : ' static > SystemLabel for ReadSystem < E > {
194
+ fn as_str ( & self ) -> & ' static str {
195
+ // FIXME: using `type_name` for equality is kinda sketchy,
196
+ // but we won't need it after https://github.com/bevyengine/bevy/pull/5377.
197
+ // This *should* be fine for the time being though, as the behavior
198
+ // of `type_name` is only subject to change between compiler versions,
199
+ // so the only place it might be able to cause issues is with dynamic plugins.
200
+ std:: any:: type_name :: < Self > ( )
201
+ }
202
+ }
189
203
190
- impl < E : Event > Default for ReadSystem < E > {
191
- fn default ( ) -> Self {
192
- Self ( PhantomData )
204
+ ReadSystem :: < E > ( PhantomData )
193
205
}
194
206
}
195
207
196
208
/// Reads events of type `T` in order and tracks which events have already been read.
197
209
#[ derive( SystemParam ) ]
198
- #[ system_param( label = ReadSystem :: <E >:: default ( ) ) ]
210
+ #[ system_param( label = Reads :: from :: <E >( ) ) ]
199
211
pub struct EventReader < ' w , ' s , E : Event > {
200
212
reader : Local < ' s , ManualEventReader < E > > ,
201
213
events : Res < ' w , Events < E > > ,
@@ -263,14 +275,21 @@ impl<'w, 's, E: Event> EventReader<'w, 's, E> {
263
275
}
264
276
}
265
277
266
- /// [Label](SystemLabel) for a [`System`](crate::system::System) that writes events of type `E`.
267
- #[ derive( SystemLabel ) ]
268
- #[ system_label( ignore_fields) ]
269
- pub struct WriteSystem < E : Event > ( PhantomData < E > ) ;
278
+ /// [Label](SystemLabel) for a [`System`](crate::system::System) that can write events of type `E`.
279
+ pub struct Writes ( ( ) ) ;
270
280
271
- impl < E : Event > Default for WriteSystem < E > {
272
- fn default ( ) -> Self {
273
- Self ( PhantomData )
281
+ impl Writes {
282
+ /// Returns a [`SystemLabel`] for a system that can write events of type `E`.
283
+ pub fn to < E : Event > ( ) -> impl SystemLabel {
284
+ struct WriteSystem < E > ( PhantomData < E > ) ;
285
+
286
+ impl < E : ' static > SystemLabel for WriteSystem < E > {
287
+ fn as_str ( & self ) -> & ' static str {
288
+ std:: any:: type_name :: < E > ( )
289
+ }
290
+ }
291
+
292
+ WriteSystem :: < E > ( PhantomData )
274
293
}
275
294
}
276
295
@@ -318,7 +337,7 @@ impl<E: Event> Default for WriteSystem<E> {
318
337
/// ```
319
338
/// Note that this is considered *non-idiomatic*, and should only be used when `EventWriter` will not work.
320
339
#[ derive( SystemParam ) ]
321
- #[ system_param( label = WriteSystem :: <E >:: default ( ) ) ]
340
+ #[ system_param( label = Writes :: to :: <E >( ) ) ]
322
341
pub struct EventWriter < ' w , ' s , E : Event > {
323
342
events : ResMut < ' w , Events < E > > ,
324
343
#[ system_param( ignore) ]
0 commit comments