Description
Currently, bevy_ecs::event::EventId
makes use of derive macros for its implementations of a set of traits:
#[derive(Eq, PartialEq, Ord, PartialOrd, Hash)]
pub struct EventId<E: Event> {
pub id: usize,
_marker: PhantomData<E>,
}
This creates an issue when attempting to actually use these implementations (especially that of Hash
), as it requires them to be implemented on the events themselves; despite the generic only being used in a marker type.
It would be better to manually implement these traits to ignore the marker, freeing them up to be used in more places than they are currently:
error[E0599]: the method `insert` exists for struct `Local<'_, HashSet<EventId<MouseButtonInput>>>`, but its trait bounds were not satisfied
--> src\interaction.rs:327:54
|
327 | if !old_events.contains(&id) && processed_events.insert(id) {
| ^^^^^^
|
::: D:\Programs\Rust\cargo\registry\src\github.com-1ecc6299db9ec823\bevy_ecs-0.10.0\src\event.rs:20:1
|
20 | pub struct EventId<E: Event> {
| ---------------------------- doesn't satisfy `bevy::ecs::event::EventId<MouseButtonInput>: Hash`
|
= note: the following trait bounds were not satisfied:
`bevy::ecs::event::EventId<MouseButtonInput>: Hash`
In the above error message, I am unable to insert an EventId
object into a HashSet
as MouseButtonInput
does not implement Hash
. As MouseButtonInput
is only being used in a marker, I don't believe it should be relied upon in the Hash
implementation; however the derive macro is not smart enough to know this. For this reason, I believe the traits should be implemented manually.