goud_engine/core/event/traits.rs
1//! The [`Event`] marker trait and its blanket implementation.
2
3/// Marker trait for types that can be sent through the event system.
4///
5/// This trait is automatically implemented for any type that satisfies
6/// `Send + Sync + 'static`. These bounds ensure:
7///
8/// - `Send`: Events can be transferred between threads
9/// - `Sync`: Event references can be shared between threads
10/// - `'static`: Events don't contain borrowed data
11///
12/// # Blanket Implementation
13///
14/// You don't need to manually implement this trait. Any type meeting the
15/// bounds automatically qualifies:
16///
17/// ```rust
18/// use goud_engine::core::event::Event;
19///
20/// struct MyEvent {
21/// data: i32,
22/// }
23///
24/// // This compiles because MyEvent is Send + Sync + 'static
25/// fn accepts_event<E: Event>(_: E) {}
26/// accepts_event(MyEvent { data: 42 });
27/// ```
28///
29/// # Non-Qualifying Types
30///
31/// Types with non-static lifetimes or non-thread-safe internals won't
32/// implement Event:
33///
34/// ```compile_fail
35/// use std::rc::Rc;
36/// use goud_engine::core::event::Event;
37///
38/// struct BadEvent {
39/// data: Rc<i32>, // Rc is not Send
40/// }
41///
42/// fn accepts_event<E: Event>(_: E) {}
43/// accepts_event(BadEvent { data: Rc::new(42) }); // Won't compile
44/// ```
45pub trait Event: Send + Sync + 'static {}
46
47/// Blanket implementation of Event for all qualifying types.
48///
49/// This ensures any `Send + Sync + 'static` type can be used as an event
50/// without explicit implementation.
51impl<T: Send + Sync + 'static> Event for T {}