Skip to content

Commit

Permalink
Dynamic into/to helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
ecton committed Nov 9, 2023
1 parent a2e28cb commit 897880d
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,28 @@ impl<T> Dynamic<T> {
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<U>(&self) -> Dynamic<U>
where
U: From<T> + 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<U>(&self) -> Dynamic<U>
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<F>(&self, mut for_each: F)
Expand Down

0 comments on commit 897880d

Please sign in to comment.