fix: allow eventhandler to derive default

This commit is contained in:
Jonathan Kelley 2022-01-15 20:17:48 -05:00
parent 8e842231e4
commit e47ead5347

View file

@ -351,8 +351,9 @@ type ExternalListenerCallback<'bump, T> = BumpBox<'bump, dyn FnMut(T) + 'bump>;
/// }
///
/// ```
#[derive(Default)]
pub struct EventHandler<'bump, T = ()> {
pub callback: &'bump RefCell<Option<ExternalListenerCallback<'bump, T>>>,
pub callback: RefCell<Option<ExternalListenerCallback<'bump, T>>>,
}
impl<T> EventHandler<'_, T> {
@ -367,15 +368,6 @@ impl<T> EventHandler<'_, T> {
}
}
impl<T> Copy for EventHandler<'_, T> {}
impl<T> Clone for EventHandler<'_, T> {
fn clone(&self) -> Self {
Self {
callback: self.callback,
}
}
}
/// Virtual Components for custom user-defined components
/// Only supports the functional syntax
pub struct VComponent<'src> {
@ -677,7 +669,7 @@ impl<'a> NodeFactory<'a> {
pub fn event_handler<T>(self, f: impl FnMut(T) + 'a) -> EventHandler<'a, T> {
let handler: &mut dyn FnMut(T) = self.bump.alloc(f);
let caller = unsafe { BumpBox::from_raw(handler as *mut dyn FnMut(T)) };
let callback = self.bump.alloc(RefCell::new(Some(caller)));
let callback = RefCell::new(Some(caller));
EventHandler { callback }
}
}