[][src]Struct reax::EagerCompute

pub struct EagerCompute<'f, C: 'f> {
    pub context: C,
    // some fields omitted
}

A helper which eagerly updates any outdated variables it is given.

The run method can be used to integrate with an async runtime. Otherwise, updates are performed by repeatedly calling tick.

Fields

context: C

The data passed to each computed variable on update.

Implementations

impl<'f, C> EagerCompute<'f, C>[src]

pub fn new(context: C) -> Self[src]

Creates a new eagerly updating environment. It will only evaluate variables that have been passed explicitly.

pub fn install<V>(&mut self, computed: ComputedVar<V>) where
    V: ComputedValue<Value = (), Context = C> + 'f, 
[src]

Add the given empty computed variable to this environment. The variable will be recomputed every time tick is called if needed. This is a good way to watch many variables at once.

Note that outdated or uncomputed variables will be computed immediately when first installed.

let a = Var::new(1);
let b = Var::new(2);

let mut eval = EagerCompute::new(());
eval.install(computed! {
   a.get();
   b.get();
   println!("a or b changed")
});

pub fn install_boxed(&mut self, computed: BoxedComputedVar<'f, (), C>)[src]

Like install but relies on the user to pre-box the computed cell.

pub fn uninstall_by_id(
    &mut self,
    node_id: usize
) -> Option<BoxedComputedVar<'f, (), C>>
[src]

Removes the computed variable with the given node id from this environment.

pub fn tick(&mut self)[src]

Recompute any installed variables which are outdated. This method may deadlock if two watchers repeatedly trigger each-other in a loop. If that is an issue, try using tick_timeout.

pub fn tick_timeout(&mut self, end: Instant) -> bool[src]

Recompute any installed variables which are outdated. This method will return true if all variables are up-to-date or false if the end time was reached first.

pub async fn run_once<'_>(&'_ mut self) -> usize[src]

Returns a future which updates a few installed variables once they become outdated then resolves to the number of updates performed. This is similar to run_forever except it only runs until at least 1 update has occurred.

pub async fn run_forever(__arg0: Self)[src]

Returns a future which runs until dropped, updating any installed variables when they become outdated. This works well with async event schedulers since the future will yield until a Var used by this environment is manually changed, at which point the future's context will be instantly notified by Node::on_write.

impl<'f> EagerCompute<'f, ()>[src]

pub fn watch<V: Variable + 'f>(
    &mut self,
    var: V,
    watcher: impl FnMut(&V::Value) + 'f
)
[src]

Call a function whenever the given variable is changed and tick is called.

let a = Var::new(1);

let mut eval = EagerCompute::new(());
eval.watch(&a, |a| println!("a changed to {}", a));

pub fn dbg<V: Variable + 'f>(&mut self, var: V) where
    V::Value: Debug
[src]

Print the value of the given variable to stderr whenever it changes and tick is called.

Trait Implementations

impl<'f, C: Default> Default for EagerCompute<'f, C>[src]

Auto Trait Implementations

impl<'f, C> !RefUnwindSafe for EagerCompute<'f, C>

impl<'f, C> !Send for EagerCompute<'f, C>

impl<'f, C> !Sync for EagerCompute<'f, C>

impl<'f, C> Unpin for EagerCompute<'f, C> where
    C: Unpin

impl<'f, C> !UnwindSafe for EagerCompute<'f, C>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.