pub struct Var<T> { /* private fields */ }
Expand description
A mutable variable that is tracked by the reax runtime.
Today this is a wrapper around a RefCell
and a Node
but may be more
generic in the future once GATs are stable.
Implementations§
Source§impl<T> Var<T>
impl<T> Var<T>
Sourcepub fn set(&self, value: T)
pub fn set(&self, value: T)
Sets the value of the variable, instantly marking all upstream variables
as dirty. This method will panic if any reference given by a call to
mutate
is still alive.
let var = Var::new(1);
let double = computed! { var.get_copy() * 2 };
var.set(2);
assert!(double.node().is_dirty());
Sourcepub fn set_checked(&self, value: T)where
T: PartialEq,
pub fn set_checked(&self, value: T)where
T: PartialEq,
Sets the value of the variable. Unlike set
, upstream
variables are not marked as dirty if the given value is equal to the
current value.
Sourcepub fn mutate(&self) -> RefMut<'_, T>
pub fn mutate(&self) -> RefMut<'_, T>
Provides a mutable reference to the variable, instantly marking all
upstream variables as dirty. This method will panic if any reference
given by a previous call to mutate
is still alive.
let var = Var::new(1);
let double = computed! { var.get_copy() * 2 };
*var.mutate() += 1;
assert!(double.node().is_dirty());
Trait Implementations§
Source§impl<T> Variable for Var<T>
impl<T> Variable for Var<T>
Source§fn node(&self) -> &Node
fn node(&self) -> &Node
Returns a handle to this variable’s node in the reax
runtime’s dependency graph.
Source§fn get_non_reactive(&self) -> Ref<'_, T>
fn get_non_reactive(&self) -> Ref<'_, T>
Returns the value of this variable without alerting the reax runtime
that the variable is used in the current context. See also
get
.Source§fn get_copy(&self) -> Self::Value
fn get_copy(&self) -> Self::Value
Returns the value of this variable by copy where possible. See also
get
.Source§fn map<T, F>(self, func: F) -> ComputedVar<FunctionMapped<Self, T, F>>
fn map<T, F>(self, func: F) -> ComputedVar<FunctionMapped<Self, T, F>>
Create a new
ComputedVar
which depends only on this variable. The
value of the returned cell is lazily computed by the given function.
That is, the function will not be executed until someone retrieves the
value of the cell. This can be used similarly to
EagerCompute::watch
if the
resulting cell is checked frequently. See also
ComputedVar::new
. Read moreSource§fn map_mutate<T, F>(
self,
initial: T,
func: F,
) -> ComputedVar<MutatorMapped<Self, T, F>>
fn map_mutate<T, F>( self, initial: T, func: F, ) -> ComputedVar<MutatorMapped<Self, T, F>>
Create a new
ComputedVar
which depends only on this variable. The
value of the returned cell is lazily updated by the given function. That
is, the function will not be executed until someone retrieves the value
of the cell. This can be used similarly to
EagerCompute::watch
if the
resulting cell is checked frequently. See also
ComputedVar::new_mutate
. Read moreSource§fn with_label(self, label: impl Display) -> Self
fn with_label(self, label: impl Display) -> Self
Provides the runtime with a variable name to use in debug outputs. This
does nothing in release builds.
Auto Trait Implementations§
impl<T> !Freeze for Var<T>
impl<T> !RefUnwindSafe for Var<T>
impl<T> !Send for Var<T>
impl<T> !Sync for Var<T>
impl<T> Unpin for Var<T>where
T: Unpin,
impl<T> UnwindSafe for Var<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more