From 897880de25abe61e2eed8a52e2e32764ee5e2007 Mon Sep 17 00:00:00 2001 From: Jonathan Johnson Date: Thu, 9 Nov 2023 10:15:13 -0800 Subject: [PATCH] Dynamic into/to helpers --- src/value.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/value.rs b/src/value.rs index ce5a776..2fdb67a 100644 --- a/src/value.rs +++ b/src/value.rs @@ -47,6 +47,28 @@ impl Dynamic { self.0.map_mut(|value, _| map(value)) } + /// Returns a new dynamic that is updated using `U::from(T.clone())` each + /// time `self` is updated. + #[must_use] + pub fn map_each_into(&self) -> Dynamic + where + U: From + Send + 'static, + T: Clone, + { + self.map_each(|value| U::from(value.clone())) + } + + /// Returns a new dynamic that is updated using `U::from(&T)` each + /// time `self` is updated. + #[must_use] + pub fn map_each_to(&self) -> Dynamic + where + U: for<'a> From<&'a T> + Send + 'static, + T: Clone, + { + self.map_each(|value| U::from(value)) + } + /// Attaches `for_each` to this value so that it is invoked each time the /// value's contents are updated. pub fn for_each(&self, mut for_each: F)