From 3f9b651f33e57a7d90bd26d43fca3ec1a621db16 Mon Sep 17 00:00:00 2001 From: Philipp Mildenberger Date: Sun, 28 Jul 2024 22:58:28 +0200 Subject: [PATCH] xilem_web: Fix #459, and add `.boxed()` combinator --- xilem_web/src/lib.rs | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/xilem_web/src/lib.rs b/xilem_web/src/lib.rs index 70c8d5c45..307f01e28 100644 --- a/xilem_web/src/lib.rs +++ b/xilem_web/src/lib.rs @@ -88,7 +88,7 @@ where } /// A view which can have any [`DomView`] type, see [`AnyView`] for more details. -pub type AnyDomView = dyn AnyView; +pub type AnyDomView = dyn AnyView; /// The central [`View`] derived trait to represent DOM nodes in xilem_web, it's the base for all [`View`]s in xilem_web pub trait DomView: @@ -97,6 +97,26 @@ pub trait DomView: type DomNode: DomNode; type Props; + /// Returns a boxed type erased [`AnyDomView`] + /// + /// # Examples + /// ``` + /// use xilem_web::{elements::html::div, DomView}; + /// + /// # fn view() -> impl DomView { + /// div("a label").boxed() + /// # } + /// + /// ``` + fn boxed(self) -> Box> + where + State: 'static, + Action: 'static, + Self: Sized, + { + Box::new(self) + } + /// See [`adapt`](`core::adapt`) fn adapt( self,