@@ -306,19 +306,12 @@ fn internal_event_reader<'a, T>(
306
306
}
307
307
}
308
308
/// Sends events of type `T`.
309
+ #[ derive( SystemParam ) ]
309
310
pub struct EventWriter < ' a , T : Component > {
310
- events : & ' a mut Events < T > ,
311
- }
312
-
313
- impl < ' a , T : Component > SystemParam for EventWriter < ' a , T > {
314
- type Fetch = ResMutState < Events < T > > ;
311
+ events : ResMut < ' a , Events < T > > ,
315
312
}
316
313
317
314
impl < ' a , T : Component > EventWriter < ' a , T > {
318
- pub fn new ( events : & ' a mut Events < T > ) -> Self {
319
- EventWriter :: < ' a , T > { events }
320
- }
321
-
322
315
pub fn send ( & mut self , event : T ) {
323
316
self . events . send ( event) ;
324
317
}
@@ -329,13 +322,10 @@ impl<'a, T: Component> EventWriter<'a, T> {
329
322
}
330
323
331
324
/// Reads events of type `T` in order and tracks which events have already been read.
325
+ #[ derive( SystemParam ) ]
332
326
pub struct EventReader < ' a , T : Component > {
333
327
last_event_count : Local < ' a , ( usize , PhantomData < T > ) > ,
334
- events : & ' a Events < T > ,
335
- }
336
-
337
- impl < ' a , T : Component > SystemParam for EventReader < ' a , T > {
338
- type Fetch = ResState < Events < T > > ;
328
+ events : Res < ' a , Events < T > > ,
339
329
}
340
330
341
331
impl < ' a , T : Component > EventReader < ' a , T > {
@@ -361,22 +351,19 @@ impl<'a, T: Component> EventReader<'a, T> {
361
351
/// allowing events to accumulate on your components or resources until consumed.
362
352
/// Note: due to the draining nature of this reader, you probably only want one
363
353
/// EventConsumer per event storage location + event type combination.
354
+ #[ derive( SystemParam ) ]
364
355
pub struct EventConsumer < ' a , T : Component > {
365
- events : & ' a mut Events < T > ,
366
- }
367
-
368
- impl < ' a , T : Component > SystemParam for EventConsumer < ' a , T > {
369
- type Fetch = ResMutState < Events < T > > ;
356
+ events : ResMut < ' a , Events < T > > ,
370
357
}
371
358
372
359
impl < ' a , T : Component > EventConsumer < ' a , T > {
373
360
/// Drains all available events this EventConsumer has access to into an iterator
374
- pub fn drain ( self ) -> impl DoubleEndedIterator < Item = T > + ' a {
361
+ pub fn drain ( self ) -> impl DoubleEndedIterator < Item = T > {
375
362
self . events . drain ( )
376
363
}
377
364
378
365
/// Drains all available events this EventConsumer has access to into an iterator and returns the id
379
- pub fn drain_with_id ( self ) -> impl DoubleEndedIterator < Item = ( T , EventId < T > ) > + ' a {
366
+ pub fn drain_with_id ( self ) -> impl DoubleEndedIterator < Item = ( T , EventId < T > ) > {
380
367
self . events . drain_with_id ( )
381
368
}
382
369
}
0 commit comments