bevy icon indicating copy to clipboard operation
bevy copied to clipboard

Require `#[derive(Event)]` on all Events

Open CatThingy opened this issue 2 years ago • 5 comments

Objective

Be consistent with Resources and Components and have Event types be more self-documenting.
Although not susceptible to accidentally using a function instead of a value due to Events only being initialized by their type, much of the same reasoning for removing the blanket impl on Resource also applies here.

  • Not immediately obvious if a type is intended to be an event
  • Prevent invisible conflicts if the same third-party or primitive types are used as events
  • Allows for further extensions (e.g. opt-in warning for missed events)

Solution

Remove the blanket impl for the Event trait. Add a derive macro for it.


Changelog

  • Event is no longer implemented for all applicable types. Add the #[derive(Event)] macro for events.

Migration Guide

  • Add the #[derive(Event)] macro for events. Third-party types used as events should be wrapped in a newtype.

CatThingy avatar Jan 04 '23 01:01 CatThingy

Closing as this does not improve the developer experience in isolation.

CatThingy avatar Mar 07 '23 20:03 CatThingy

I don't agree. Admittedly, it was only once, but this feature would have saved me an hour of debugging when I mistakenly used the wrong type in an EventReader.

nicopap avatar Mar 07 '23 21:03 nicopap

@CatThingy can you consider re-opening this? Most people seem to think this PR is a good idea.

joseph-gio avatar Mar 09 '23 14:03 joseph-gio

Doesn't this need documentation changes? Migration instructions?

targrub avatar Mar 10 '23 22:03 targrub

Doesn't this need documentation changes? Migration instructions?

Documentation changes I actually don't think are needed: the blog post will contain a blurb and the examples will all demonstrate the pattern.

Migration guide is done: it's just adding a derive and newtyping when needed. People are used to this with components and resources already.

alice-i-cecile avatar Mar 10 '23 22:03 alice-i-cecile

@CatThingy can you get this passing CI? Once that's done we'll finally merge this in :)

alice-i-cecile avatar Jun 05 '23 22:06 alice-i-cecile