diff --git a/crates/bevy_ecs/src/event.rs b/crates/bevy_ecs/src/event.rs index f0e5f26f74cf2a..d89de569a7af92 100644 --- a/crates/bevy_ecs/src/event.rs +++ b/crates/bevy_ecs/src/event.rs @@ -4,7 +4,14 @@ use crate as bevy_ecs; use crate::system::{Local, Res, ResMut, Resource, SystemParam}; use bevy_utils::detailed_trace; use std::ops::{Deref, DerefMut}; -use std::{fmt, hash::Hash, iter::Chain, marker::PhantomData, slice::Iter}; +use std::{ + cmp::Ordering, + fmt, + hash::{Hash, Hasher}, + iter::Chain, + marker::PhantomData, + slice::Iter, +}; /// A type that can be stored in an [`Events`] resource /// You can conveniently access events using the [`EventReader`] and [`EventWriter`] system parameter. /// @@ -16,7 +23,6 @@ impl Event for T where T: Send + Sync + 'static {} /// /// An `EventId` can among other things be used to trace the flow of an event from the point it was /// sent to the point it was processed. -#[derive(Eq, PartialEq, Ord, PartialOrd, Hash)] pub struct EventId { pub id: usize, _marker: PhantomData, @@ -46,6 +52,32 @@ impl fmt::Debug for EventId { } } +impl PartialEq for EventId { + fn eq(&self, other: &Self) -> bool { + self.id == other.id + } +} + +impl Eq for EventId {} + +impl PartialOrd for EventId { + fn partial_cmp(&self, other: &Self) -> Option { + Some(self.id.cmp(&other.id)) + } +} + +impl Ord for EventId { + fn cmp(&self, other: &Self) -> Ordering { + self.id.cmp(&other.id) + } +} + +impl Hash for EventId { + fn hash(&self, state: &mut H) { + Hash::hash(&self.id, state); + } +} + #[derive(Debug)] struct EventInstance { pub event_id: EventId,