Skip to main content

euv_core/event/handler/
struct.rs

1use super::*;
2
3/// A wrapper around an event callback.
4///
5/// Stores the event name and a shared reference to the callback closure.
6/// Uses `Rc<UnsafeCell<>>` instead of `Rc<RefCell<>>` to avoid runtime
7/// borrow checking overhead in the single-threaded WASM context.
8/// The `Rc` provides automatic memory management (freed when last reference drops).
9#[derive(Clone, CustomDebug, Data, New)]
10#[new(pub(crate))]
11pub struct NativeEventHandler {
12    /// The name of the event (e.g., "click", "input").
13    #[get(type(copy))]
14    #[get_mut(pub(crate))]
15    #[set(pub(crate))]
16    #[get(pub(crate))]
17    #[get_mut(pub(crate))]
18    #[set(pub(crate))]
19    pub(crate) event_name: &'static str,
20    /// Shared reference to the callback closure.
21    /// `UnsafeCell` allows mutable access without RefCell overhead.
22    /// Safety: only accessed from the main thread in WASM single-threaded context.
23    #[debug(skip)]
24    #[get(pub(crate))]
25    #[get_mut(pub(crate))]
26    #[set(pub(crate))]
27    #[get(pub(crate))]
28    #[get_mut(pub(crate))]
29    #[set(pub(crate))]
30    pub(crate) callback: SharedEventCallback,
31}