From 25a9ab7b7f9548b70e40ad40232bd7a2c84a9df4 Mon Sep 17 00:00:00 2001 From: Filipe Rodrigues Date: Fri, 16 May 2025 17:43:04 +0100 Subject: [PATCH] Updated bounds depending on `WithDefault`'s `SignalWith` impl. --- dynatos/src/element_dyn_attr.rs | 22 +++++----------------- dynatos/src/node_dyn_text.rs | 18 +++--------------- dynatos/src/object_dyn_prop.rs | 13 +++---------- 3 files changed, 11 insertions(+), 42 deletions(-) diff --git a/dynatos/src/element_dyn_attr.rs b/dynatos/src/element_dyn_attr.rs index 45c2f06..b708c0e 100644 --- a/dynatos/src/element_dyn_attr.rs +++ b/dynatos/src/element_dyn_attr.rs @@ -3,6 +3,7 @@ // Imports use { crate::ObjectAttachEffect, + core::ops::Deref, dynatos_html::WeakRef, dynatos_reactive::{Derived, Effect, Memo, Signal, SignalWith, WithDefault}, dynatos_router::QuerySignal, @@ -156,7 +157,8 @@ where [T] [Signal where T: WithDynAttr + 'static]; [T, F] [Derived where T: WithDynAttr + 'static, F: ?Sized + 'static]; [T, F] [Memo where T: WithDynAttr + 'static, F: ?Sized + 'static]; - [S, T] [WithDefault where S: for<'a> SignalWith = Option<&'a T>>, T: WithDynAttr + 'static]; + [S, T] [WithDefault where Self: for<'a> SignalWith: Sized + Deref>]; + [T] [QuerySignal where T: WithDynAttr + 'static]; )] impl WithDynAttr for Ty { fn with_attr(&self, f: F2) -> O @@ -166,20 +168,6 @@ impl WithDynAttr for Ty { self.with(|text| text.with_attr(f)) } } -impl WithDynAttr for QuerySignal -where - T: WithDynAttr + 'static, -{ - fn with_attr(&self, f: F2) -> O - where - F2: FnOnce(Option<&str>) -> O, - { - self.with(|text| match text { - Some(text) => text.with_attr(f), - None => None::.with_attr(f), - }) - } -} /// Trait for values accepted by [`ElementDynAttr::set_dyn_attr_if`]. /// @@ -216,10 +204,10 @@ impl DynAttrPred for bool { [T] [Signal where T: DynAttrPred + 'static]; [T, F] [Derived where T: DynAttrPred + 'static, F: ?Sized + 'static]; [T, F] [Memo where T: DynAttrPred + 'static, F: ?Sized + 'static]; - [S, T] [WithDefault where S: for<'a> SignalWith = Option<&'a T>>, T: DynAttrPred + 'static]; + [S, T] [WithDefault where Self: for<'a> SignalWith: Sized + Deref>]; )] impl DynAttrPred for Ty { fn eval(&self) -> bool { - self.with(T::eval) + self.with(|value| value.eval()) } } diff --git a/dynatos/src/node_dyn_text.rs b/dynatos/src/node_dyn_text.rs index ff8a9a4..ded6350 100644 --- a/dynatos/src/node_dyn_text.rs +++ b/dynatos/src/node_dyn_text.rs @@ -3,6 +3,7 @@ // Imports use { crate::ObjectAttachEffect, + core::ops::Deref, dynatos_html::WeakRef, dynatos_reactive::{Derived, Effect, Memo, Signal, SignalWith, WithDefault}, dynatos_router::QuerySignal, @@ -124,7 +125,8 @@ where [T] [Signal where T: WithDynText + 'static]; [T, F] [Derived where T: WithDynText + 'static, F: ?Sized + 'static]; [T, F] [Memo where T: WithDynText + 'static, F: ?Sized + 'static]; - [S, T] [WithDefault where S: for<'a> SignalWith = Option<&'a T>>, T: WithDynText + 'static]; + [S, T] [WithDefault where Self: for<'a> SignalWith: Sized + Deref>]; + [T] [QuerySignal where T: WithDynText + 'static]; )] impl WithDynText for Ty { fn with_text(&self, f: F2) -> O @@ -134,17 +136,3 @@ impl WithDynText for Ty { self.with(|text| text.with_text(f)) } } -impl WithDynText for QuerySignal -where - T: WithDynText + 'static, -{ - fn with_text(&self, f: F2) -> O - where - F2: FnOnce(Option<&str>) -> O, - { - self.with(|text| match text { - Some(text) => text.with_text(f), - None => None::.with_text(f), - }) - } -} diff --git a/dynatos/src/object_dyn_prop.rs b/dynatos/src/object_dyn_prop.rs index 78aef00..344e286 100644 --- a/dynatos/src/object_dyn_prop.rs +++ b/dynatos/src/object_dyn_prop.rs @@ -3,6 +3,7 @@ // Imports use { crate::ObjectAttachEffect, + core::ops::Deref, dynatos_html::{ObjectRemoveProp, ObjectSetProp, WeakRef}, dynatos_reactive::{Derived, Effect, Memo, Signal, SignalWith, WithDefault}, dynatos_router::QuerySignal, @@ -151,19 +152,11 @@ impl ToDynProp for Ty { [T] [Signal where T: ToDynProp + 'static]; [T, F] [Derived where T: ToDynProp + 'static, F: ?Sized + 'static]; [T, F] [Memo where T: ToDynProp + 'static, F: ?Sized + 'static]; - [S, T] [WithDefault where S: for<'a> SignalWith = Option<&'a T>>, T: ToDynProp + 'static]; + [S, T] [WithDefault where Self: for<'a> SignalWith: Sized + Deref>]; + [T] [QuerySignal where T: ToDynProp + 'static]; )] impl ToDynProp for Ty { fn to_prop(&self) -> Option { self.with(|prop| prop.to_prop()) } } - -impl ToDynProp for QuerySignal -where - T: ToDynProp + 'static, -{ - fn to_prop(&self) -> Option { - self.with(|prop| prop.as_ref().and_then(T::to_prop)) - } -}