diff options
Diffstat (limited to 'ecs/src/event.rs')
-rw-r--r-- | ecs/src/event.rs | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/ecs/src/event.rs b/ecs/src/event.rs new file mode 100644 index 0000000..0cf6da7 --- /dev/null +++ b/ecs/src/event.rs @@ -0,0 +1,24 @@ +use std::any::TypeId; +use std::fmt::Debug; +use std::hash::Hash; + +pub trait Event: Debug + 'static +{ + fn id(&self) -> Id; +} + +/// The ID of a [`Event`]. +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] +pub struct Id +{ + inner: TypeId, +} + +impl Id +{ + /// Returns the id of a [`Event`]; + pub fn of<EventT: Event>() -> Self + { + Self { inner: TypeId::of::<EventT>() } + } +} |