feat: fix some lifetime issues

This commit is contained in:
Jonathan Kelley 2021-07-24 00:40:34 -04:00
parent dfaf5adee1
commit 0a907b35c6
2 changed files with 11 additions and 5 deletions

View file

@ -138,6 +138,7 @@ pub mod on {
//!
#![allow(unused)]
use bumpalo::boxed::Box as BumpBox;
use std::{cell::RefCell, fmt::Debug, ops::Deref, rc::Rc};
use crate::{
@ -182,14 +183,18 @@ pub mod on {
where F: FnMut($wrapper) + 'a
{
let bump = &c.bump();
let cb: &mut dyn FnMut(VirtualEvent) = bump.alloc(move |evt: VirtualEvent| match evt {
VirtualEvent::$wrapper(event) => callback(event),
_ => unreachable!("Downcasted VirtualEvent to wrong event type - this is an internal bug!")
});
let callback: BumpBox<dyn FnMut(VirtualEvent) + 'a> = unsafe { BumpBox::from_raw(cb) };
Listener {
event: stringify!($name),
mounted_node: Cell::new(None),
scope: c.scope.our_arena_idx,
callback: RefCell::new(bump.alloc(move |evt: VirtualEvent| match evt {
VirtualEvent::$wrapper(event) => callback(event),
_ => unreachable!("Downcasted VirtualEvent to wrong event type - this is an internal bug!")
})),
callback: RefCell::new(callback),
}
}
)*

View file

@ -7,6 +7,7 @@ use crate::{
events::VirtualEvent,
innerlude::{empty_cell, Context, DomTree, ElementId, Properties, Scope, ScopeId, FC},
};
use bumpalo::boxed::Box as BumpBox;
use std::{
cell::{Cell, RefCell},
fmt::{Arguments, Debug, Formatter},
@ -112,7 +113,7 @@ pub struct Listener<'bump> {
pub mounted_node: Cell<Option<ElementId>>,
pub(crate) callback: RefCell<&'bump mut dyn FnMut(VirtualEvent)>,
pub(crate) callback: RefCell<BumpBox<'bump, dyn FnMut(VirtualEvent) + 'bump>>,
}
/// Virtual Components for custom user-defined components