Skip to main content

euv_core/event/handler/
struct.rs

1use crate::*;
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)]
10pub struct NativeEventHandler {
11    /// The name of the event (e.g., "click", "input").
12    #[get(pub(crate), type(copy))]
13    #[get_mut(pub(crate))]
14    #[set(pub(crate))]
15    pub(crate) event_name: &'static str,
16    /// Shared reference to the callback closure.
17    /// `UnsafeCell` allows mutable access without RefCell overhead.
18    /// Safety: only accessed from the main thread in WASM single-threaded context.
19    #[debug(skip)]
20    #[get(pub(crate))]
21    #[get_mut(pub(crate))]
22    #[set(pub(crate))]
23    pub(crate) callback: SharedEventCallback,
24}