pub struct Var<'c, T>(/* private fields */);
Expand description
Implementations§
Source§impl<'c, T> Var<'c, T>
impl<'c, T> Var<'c, T>
Sourcepub fn set<'a>(self, c: impl MutRxContext<'a, 'c>, value: T)where
'c: 'a,
pub fn set<'a>(self, c: impl MutRxContext<'a, 'c>, value: T)where
'c: 'a,
Write a new value to the variable. The changes will be applied on recompute.
Sourcepub fn modify<'a, F: FnOnce(&T) -> T>(
self,
c: impl MutRxContext<'a, 'c>,
modify: F,
)where
'c: 'a,
pub fn modify<'a, F: FnOnce(&T) -> T>(
self,
c: impl MutRxContext<'a, 'c>,
modify: F,
)where
'c: 'a,
Apply a transformation to the latest value. If Var::set this will apply to the recently-set value. This must be used instead of chaining Var::set and Var::get, since setting a value doesn’t make it returned by Var::get until the graph is recomputed.
Like set
the changes only actually reflect in Var::get on recompute.
Sourcepub fn derive<U, GetFn: Fn(&T) -> &U, SetFn: Fn(&T, U) -> T>(
self,
get: GetFn,
set: SetFn,
) -> DVar<'c, T, U, GetFn, SetFn>
pub fn derive<U, GetFn: Fn(&T) -> &U, SetFn: Fn(&T, U) -> T>( self, get: GetFn, set: SetFn, ) -> DVar<'c, T, U, GetFn, SetFn>
Create a view of part of the variable.
Do know that SetFn
will take the most recently-set value even if the graph hasn’t been recomputed.
This means you can create multiple derive
s and set them all before recompute, and you don’t have to worry
about the later derived values setting their part on the stale whole.
Sourcepub fn derive_using_clone<U, GetFn: Fn(&T) -> &U, SetFn: Fn(&mut T, U)>(
self,
get: GetFn,
set: SetFn,
) -> DVar<'c, T, U, GetFn, CloneSetFn<T, U, SetFn>>where
T: Clone,
pub fn derive_using_clone<U, GetFn: Fn(&T) -> &U, SetFn: Fn(&mut T, U)>(
self,
get: GetFn,
set: SetFn,
) -> DVar<'c, T, U, GetFn, CloneSetFn<T, U, SetFn>>where
T: Clone,
Create a view of part of the variable, which clones the value on set.
Do know that SetFn
will take the most recently-set value even if the graph hasn’t been recomputed.
This means you can create multiple derive
s and set them all before recompute, and you don’t have to worry
about the later derived values setting their part on the stale whole.