diff options
author | HampusM <hampus@hampusmat.com> | 2024-03-02 12:00:01 +0100 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2024-03-02 12:00:01 +0100 |
commit | 6f8aeb236725f673f199bce7a6f3942eb56a8318 (patch) | |
tree | 5ed2b80d57f9115843be8b11118d44e6ec973215 /ecs/src/event.rs | |
parent | 7c6391c1bea40c5260f4a750adc9d3c648b05db9 (diff) |
feat(ecs): add event trait
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>() } + } +} |