diff --git a/leptos_dom/src/macro_helpers/into_attribute.rs b/leptos_dom/src/macro_helpers/into_attribute.rs index 25bf36e5a3..28307b2701 100644 --- a/leptos_dom/src/macro_helpers/into_attribute.rs +++ b/leptos_dom/src/macro_helpers/into_attribute.rs @@ -105,6 +105,7 @@ impl std::fmt::Debug for Attribute { pub trait IntoAttribute { /// Converts the object into an [`Attribute`]. fn into_attribute(self) -> Attribute; + /// Helper function for dealing with `Box`. fn into_attribute_boxed(self: Box) -> Attribute; } diff --git a/leptos_dom/src/macro_helpers/into_class.rs b/leptos_dom/src/macro_helpers/into_class.rs index 7d246227cf..152cfe4b14 100644 --- a/leptos_dom/src/macro_helpers/into_class.rs +++ b/leptos_dom/src/macro_helpers/into_class.rs @@ -21,6 +21,9 @@ pub enum Class { pub trait IntoClass { /// Converts the object into a [`Class`]. fn into_class(self) -> Class; + + /// Helper function for dealing with `Box`. + fn into_class_boxed(self: Box) -> Class; } impl IntoClass for bool { @@ -28,6 +31,10 @@ impl IntoClass for bool { fn into_class(self) -> Class { Class::Value(self) } + + fn into_class_boxed(self: Box) -> Class { + (*self).into_class() + } } impl IntoClass for T @@ -39,6 +46,10 @@ where let modified_fn = Box::new(self); Class::Fn(modified_fn) } + + fn into_class_boxed(self: Box) -> Class { + (*self).into_class() + } } impl Class { @@ -128,6 +139,10 @@ macro_rules! class_signal_type { let modified_fn = Box::new(move || self.get()); Class::Fn(modified_fn) } + + fn into_class_boxed(self: Box) -> Class { + (*self).into_class() + } } }; } @@ -141,6 +156,10 @@ macro_rules! class_signal_type_optional { let modified_fn = Box::new(move || self.get().unwrap_or(false)); Class::Fn(modified_fn) } + + fn into_class_boxed(self: Box) -> Class { + (*self).into_class() + } } }; } diff --git a/leptos_dom/src/macro_helpers/into_property.rs b/leptos_dom/src/macro_helpers/into_property.rs index df6895441b..d1bca1383c 100644 --- a/leptos_dom/src/macro_helpers/into_property.rs +++ b/leptos_dom/src/macro_helpers/into_property.rs @@ -15,7 +15,7 @@ use wasm_bindgen::UnwrapThrowExt; pub enum Property { /// A static JavaScript value. Value(JsValue), - /// A (presumably reactive) function, which will be run inside an effect to toggle the class. + /// A (presumably reactive) function, which will be run inside an effect to update the property. Fn(Box JsValue>), } @@ -25,6 +25,9 @@ pub enum Property { pub trait IntoProperty { /// Converts the object into a [`Property`]. fn into_property(self) -> Property; + + /// Helper function for dealing with `Box`. + fn into_property_boxed(self: Box) -> Property; } impl IntoProperty for T @@ -36,6 +39,10 @@ where let modified_fn = Box::new(move || self().into()); Property::Fn(modified_fn) } + + fn into_property_boxed(self: Box) -> Property { + (*self).into_property() + } } macro_rules! prop_type { @@ -45,6 +52,10 @@ macro_rules! prop_type { fn into_property(self) -> Property { Property::Value(self.into()) } + + fn into_property_boxed(self: Box) -> Property { + (*self).into_property() + } } impl IntoProperty for Option<$prop_type> { @@ -52,6 +63,10 @@ macro_rules! prop_type { fn into_property(self) -> Property { Property::Value(self.into()) } + + fn into_property_boxed(self: Box) -> Property { + (*self).into_property() + } } }; } @@ -67,6 +82,10 @@ macro_rules! prop_signal_type { let modified_fn = Box::new(move || self.get().into()); Property::Fn(modified_fn) } + + fn into_property_boxed(self: Box) -> Property { + (*self).into_property() + } } }; } @@ -83,6 +102,10 @@ macro_rules! prop_signal_type_optional { let modified_fn = Box::new(move || self.get().into()); Property::Fn(modified_fn) } + + fn into_property_boxed(self: Box) -> Property { + (*self).into_property() + } } }; } diff --git a/leptos_dom/src/macro_helpers/into_style.rs b/leptos_dom/src/macro_helpers/into_style.rs index 0d0b92b552..11c5d5cde7 100644 --- a/leptos_dom/src/macro_helpers/into_style.rs +++ b/leptos_dom/src/macro_helpers/into_style.rs @@ -41,6 +41,9 @@ impl std::fmt::Debug for Style { pub trait IntoStyle { /// Converts the object into a [`Style`]. fn into_style(self) -> Style; + + /// Helper function for dealing with `Box`. + fn into_style_boxed(self: Box) -> Style; } impl IntoStyle for &'static str { @@ -48,6 +51,10 @@ impl IntoStyle for &'static str { fn into_style(self) -> Style { Style::Value(Oco::Borrowed(self)) } + + fn into_style_boxed(self: Box) -> Style { + (*self).into_style() + } } impl IntoStyle for String { @@ -55,6 +62,10 @@ impl IntoStyle for String { fn into_style(self) -> Style { Style::Value(Oco::Owned(self)) } + + fn into_style_boxed(self: Box) -> Style { + (*self).into_style() + } } impl IntoStyle for Rc { @@ -62,6 +73,10 @@ impl IntoStyle for Rc { fn into_style(self) -> Style { Style::Value(Oco::Counted(self)) } + + fn into_style_boxed(self: Box) -> Style { + (self).into_style() + } } impl IntoStyle for Cow<'static, str> { @@ -69,6 +84,10 @@ impl IntoStyle for Cow<'static, str> { fn into_style(self) -> Style { Style::Value(self.into()) } + + fn into_style_boxed(self: Box) -> Style { + (*self).into_style() + } } impl IntoStyle for Oco<'static, str> { @@ -76,6 +95,10 @@ impl IntoStyle for Oco<'static, str> { fn into_style(self) -> Style { Style::Value(self) } + + fn into_style_boxed(self: Box) -> Style { + (*self).into_style() + } } impl IntoStyle for Option<&'static str> { @@ -83,6 +106,10 @@ impl IntoStyle for Option<&'static str> { fn into_style(self) -> Style { Style::Option(self.map(Oco::Borrowed)) } + + fn into_style_boxed(self: Box) -> Style { + (*self).into_style() + } } impl IntoStyle for Option { @@ -90,6 +117,10 @@ impl IntoStyle for Option { fn into_style(self) -> Style { Style::Option(self.map(Oco::Owned)) } + + fn into_style_boxed(self: Box) -> Style { + (self).into_style() + } } impl IntoStyle for Option> { @@ -97,6 +128,10 @@ impl IntoStyle for Option> { fn into_style(self) -> Style { Style::Option(self.map(Oco::Counted)) } + + fn into_style_boxed(self: Box) -> Style { + (*self).into_style() + } } impl IntoStyle for Option> { @@ -104,6 +139,10 @@ impl IntoStyle for Option> { fn into_style(self) -> Style { Style::Option(self.map(Oco::from)) } + + fn into_style_boxed(self: Box) -> Style { + (*self).into_style() + } } impl IntoStyle for Option> { @@ -111,6 +150,10 @@ impl IntoStyle for Option> { fn into_style(self) -> Style { Style::Option(self) } + + fn into_style_boxed(self: Box) -> Style { + (*self).into_style() + } } impl IntoStyle for T @@ -123,6 +166,10 @@ where let modified_fn = Rc::new(move || (self)().into_style()); Style::Fn(modified_fn) } + + fn into_style_boxed(self: Box) -> Style { + (*self).into_style() + } } impl Style { @@ -221,12 +268,20 @@ macro_rules! style_type { fn into_style(self) -> Style { Style::Value(self.to_string().into()) } + + fn into_style_boxed(self: Box) -> Style { + (*self).into_style() + } } impl IntoStyle for Option<$style_type> { fn into_style(self) -> Style { Style::Option(self.map(|n| n.to_string().into())) } + + fn into_style_boxed(self: Box) -> Style { + (*self).into_style() + } } }; } @@ -242,6 +297,10 @@ macro_rules! style_signal_type { let modified_fn = Rc::new(move || self.get().into_style()); Style::Fn(modified_fn) } + + fn into_style_boxed(self: Box) -> Style { + (*self).into_style() + } } }; } @@ -258,6 +317,10 @@ macro_rules! style_signal_type_optional { let modified_fn = Rc::new(move || self.get().into_style()); Style::Fn(modified_fn) } + + fn into_style_boxed(self: Box) -> Style { + (*self).into_style() + } } }; }