pub trait Variable: Sized {
type Value;
// Required methods
fn node(&self) -> &Node;
fn get(&self) -> Ref<'_, Self::Value>;
fn get_non_reactive(&self) -> Ref<'_, Self::Value>;
// Provided methods
fn get_copy(&self) -> Self::Value
where Self::Value: Copy { ... }
fn map<T, F>(self, func: F) -> ComputedVar<FunctionMapped<Self, T, F>>
where F: FnMut(&Self::Value) -> T { ... }
fn map_mutate<T, F>(
self,
initial: T,
func: F,
) -> ComputedVar<MutatorMapped<Self, T, F>>
where F: FnMut(&Self::Value, &mut T) { ... }
fn with_label(self, label: impl Display) -> Self { ... }
}
Expand description
A trait implemented by any wrapped data which reax can manage.
Required Associated Types§
Required Methods§
Sourcefn node(&self) -> &Node
fn node(&self) -> &Node
Returns a handle to this variable’s node in the reax runtime’s dependency graph.
Sourcefn get(&self) -> Ref<'_, Self::Value>
fn get(&self) -> Ref<'_, Self::Value>
Returns the value of this variable.
Note that right now this trait assumes that the data is stored behind a
RefCell
. The source of interior mutability can be made more generic
once GATs are stabilized.
Sourcefn get_non_reactive(&self) -> Ref<'_, Self::Value>
fn get_non_reactive(&self) -> Ref<'_, Self::Value>
Returns the value of this variable without alerting the reax runtime
that the variable is used in the current context. See also
get
.
Provided Methods§
Sourcefn get_copy(&self) -> Self::Value
fn get_copy(&self) -> Self::Value
Returns the value of this variable by copy where possible. See also
get
.
Sourcefn 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
.
Note that variables should usually be borrowed or Rc::clone
ed before
being passed to this function (e.g. (&variable).map(...)
).
Sourcefn 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
.
Note that variables should usually be borrowed or Rc::clone
ed before
being passed to this function (e.g. (&variable).map_mutate(...)
).
Sourcefn 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.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.