1use crate::Event;
4use std::any::TypeId;
5use std::time::Instant;
6
7#[derive(Debug, Clone)]
11pub struct EventMetadata {
12 pub event_name: &'static str,
14 pub type_id: TypeId,
16 pub last_dispatch: Instant,
18 pub dispatch_count: usize,
20 pub listener_count: usize,
22}
23
24impl EventMetadata {
25 pub(crate) fn new<T: Event>() -> Self {
26 Self {
27 event_name: std::any::type_name::<T>(),
28 type_id: TypeId::of::<T>(),
29 last_dispatch: Instant::now(),
30 dispatch_count: 0,
31 listener_count: 0,
32 }
33 }
34
35 pub(crate) fn increment_dispatch(&mut self) {
36 self.dispatch_count += 1;
37 self.last_dispatch = Instant::now();
38 }
39
40 pub(crate) fn update_listener_count(&mut self, count: usize) {
41 self.listener_count = count;
42 }
43
44 pub fn time_since_last_dispatch(&self) -> std::time::Duration {
46 self.last_dispatch.elapsed()
47 }
48}