mirror of
https://github.com/danbulant/cushy
synced 2026-06-16 21:11:20 +00:00
Dynamic into/to helpers
This commit is contained in:
parent
a2e28cb522
commit
897880de25
1 changed files with 22 additions and 0 deletions
22
src/value.rs
22
src/value.rs
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Reference in a new issue