diff --git a/xilem_web/src/elements.rs b/xilem_web/src/elements.rs index 64b937e68..bd1e16207 100644 --- a/xilem_web/src/elements.rs +++ b/xilem_web/src/elements.rs @@ -4,6 +4,7 @@ //! Basic builder functions to create DOM elements, such as [`html::div`] use std::borrow::Cow; +use std::marker::PhantomData; use std::{any::Any, rc::Rc}; use wasm_bindgen::{JsCast, UnwrapThrowExt}; @@ -290,16 +291,17 @@ pub(crate) fn teardown_element( } /// An element that can change its tag, it's useful for autonomous custom elements (i.e. web components) -pub struct CustomElement { +pub struct CustomElement { name: Cow<'static, str>, children: Box>, + phantom: PhantomData, } /// An element that can change its tag, it's useful for autonomous custom elements (i.e. web components) pub fn custom_element( name: impl Into>, children: Children, -) -> CustomElement +) -> CustomElement where State: 'static, Action: 'static, @@ -308,11 +310,14 @@ where CustomElement { name: name.into(), children: Box::new(children), + phantom: PhantomData, } } -impl ViewMarker for CustomElement {} -impl View for CustomElement +impl ViewMarker for CustomElement {} +impl View + for CustomElement where + Children: 'static, State: 'static, Action: 'static, { @@ -381,8 +386,9 @@ macro_rules! define_element { define_element!($ns, ($ty_name, $name, $dom_interface, stringify!($name))); }; ($ns:expr, ($ty_name:ident, $name:ident, $dom_interface:ident, $tag_name:expr)) => { - pub struct $ty_name { + pub struct $ty_name { children: Box>, + phantom: PhantomData, } /// Builder function for a @@ -390,15 +396,18 @@ macro_rules! define_element { /// element view. pub fn $name>( children: Children, - ) -> $ty_name { + ) -> $ty_name { $ty_name { children: Box::new(children), + phantom: PhantomData, } } - impl ViewMarker for $ty_name {} - impl View for $ty_name + impl ViewMarker for $ty_name {} + impl View + for $ty_name where + Children: 'static, State: 'static, Action: 'static, { @@ -455,6 +464,7 @@ macro_rules! define_element { macro_rules! define_elements { ($ns:ident, $($element_def:tt,)*) => { + use std::marker::PhantomData; use super::{build_element, rebuild_element, teardown_element, DomViewSequence, ElementState}; use crate::{ core::{MessageResult, Mut, ViewId, ViewMarker},