pub struct RxDAG<'c>(_, _);Expand description
The DAG is a list of interspersed nodes and edges. The edges refer to other nodes relative to their own position. Later Rxs must depend on earlier Rxs.
When the DAG recomputes, it simply iterates through each node and edge in order and calls RxDAGElem::recompute.
If the nodes were changed (directly or as edge output), they set their new value, and mark that they got recomputed.
The edges will recompute and change their output nodes if any of their inputs got recomputed.
The DAG has interior mutability, in that it can add nodes without a mutable borrow.
See elsa crate for why this is sound (though actually the soundness argument is contested).
Internally we use a modified version because of elsa and stable-deref-trait
Setting Rx values is also interior mutability, and OK because we don’t use those values until RxDAGElem::recompute.
The DAG and refs have an ID so that you can’t use one ref on another DAG, however this is checked at runtime. The lifetimes are checked at compile-time though.
Currently no Rxs are deallocated until the entire DAG is deallocated,
so if you keep creating and discarding Rxs you will leak memory (TODO fix this?)
Implementations
sourceimpl<'c> RxDAG<'c>
impl<'c> RxDAG<'c>
sourcepub fn run_crx<F: FnMut(RxInput<'_, 'c>) + 'c>(&self, compute: F)
pub fn run_crx<F: FnMut(RxInput<'_, 'c>) + 'c>(&self, compute: F)
Run a closure when inputs change, without creating any outputs (for side-effects).
sourcepub fn new_crx<T: 'c, F: FnMut(RxInput<'_, 'c>) -> T + 'c>(
&self,
compute: F
) -> CRx<'c, T>
pub fn new_crx<T: 'c, F: FnMut(RxInput<'_, 'c>) -> T + 'c>(
&self,
compute: F
) -> CRx<'c, T>
Create a computed Rx in this DAG.
sourcepub fn new_crx2<T1: 'c, T2: 'c, F: FnMut(RxInput<'_, 'c>) -> (T1, T2) + 'c>(
&self,
compute: F
) -> (CRx<'c, T1>, CRx<'c, T2>)
pub fn new_crx2<T1: 'c, T2: 'c, F: FnMut(RxInput<'_, 'c>) -> (T1, T2) + 'c>(
&self,
compute: F
) -> (CRx<'c, T1>, CRx<'c, T2>)
Create 2 computed Rx in this DAG which are created from the same function.
sourcepub fn new_crx3<T1: 'c, T2: 'c, T3: 'c, F: FnMut(RxInput<'_, 'c>) -> (T1, T2, T3) + 'c>(
&self,
compute: F
) -> (CRx<'c, T1>, CRx<'c, T2>, CRx<'c, T3>)
pub fn new_crx3<T1: 'c, T2: 'c, T3: 'c, F: FnMut(RxInput<'_, 'c>) -> (T1, T2, T3) + 'c>(
&self,
compute: F
) -> (CRx<'c, T1>, CRx<'c, T2>, CRx<'c, T3>)
Create 3 computed Rx in this DAG which are created from the same function.
sourcepub fn now(&mut self) -> RxDAGSnapshot<'_, 'c>
pub fn now(&mut self) -> RxDAGSnapshot<'_, 'c>
Recomputes if necessary and then returns a RxContext you can use to get the current value.
sourcepub fn stale(&self) -> RxDAGSnapshot<'_, 'c>
pub fn stale(&self) -> RxDAGSnapshot<'_, 'c>
Returns a RxContext you can use to get the current value.
However any newly-set values or computations will not be returned until recompute is called.
Trait Implementations
Auto Trait Implementations
impl<'c> !RefUnwindSafe for RxDAG<'c>
impl<'c> !Send for RxDAG<'c>
impl<'c> !Sync for RxDAG<'c>
impl<'c> Unpin for RxDAG<'c>
impl<'c> !UnwindSafe for RxDAG<'c>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more