Trait Variable

Source
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§

Source

type Value

The type of this variable.

Required Methods§

Source

fn node(&self) -> &Node

Returns a handle to this variable’s node in the reax runtime’s dependency graph.

Source

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.

Source

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§

Source

fn get_copy(&self) -> Self::Value
where Self::Value: Copy,

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>>
where F: FnMut(&Self::Value) -> T,

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::cloneed before being passed to this function (e.g. (&variable).map(...)).

Source

fn map_mutate<T, F>( self, initial: T, func: F, ) -> ComputedVar<MutatorMapped<Self, T, F>>
where F: FnMut(&Self::Value, &mut T),

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::cloneed before being passed to this function (e.g. (&variable).map_mutate(...)).

Source

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.

Implementations on Foreign Types§

Source§

impl<'r, T> Variable for &'r T
where T: Variable,

Source§

type Value = <T as Variable>::Value

Source§

fn node(&self) -> &Node

Source§

fn get(&self) -> Ref<'_, Self::Value>

Source§

fn get_non_reactive<'a>(&self) -> Ref<'_, Self::Value>

Source§

impl<T> Variable for Box<T>
where T: Variable,

Source§

type Value = <T as Variable>::Value

Source§

fn node(&self) -> &Node

Source§

fn get(&self) -> Ref<'_, Self::Value>

Source§

fn get_non_reactive<'a>(&self) -> Ref<'_, Self::Value>

Source§

impl<T> Variable for Rc<T>
where T: Variable,

Source§

type Value = <T as Variable>::Value

Source§

fn node(&self) -> &Node

Source§

fn get(&self) -> Ref<'_, Self::Value>

Source§

fn get_non_reactive<'a>(&self) -> Ref<'_, Self::Value>

Implementors§

Source§

impl<C: ComputedValue<Context = ()>> Variable for ComputedVar<C>

Source§

impl<T> Variable for Var<T>

Source§

type Value = T