Crate mini_rx

Source
Expand description

Rx means “reactive value” (or “reactive X”). It is a wrapper for a value which changes, and these changes trigger dependencies to re-run and change themselves.

Because of Rust’s borrowing rules, you can’t just have Rx values change arbitrarily, because then references will be invalidated. Instead, when an Rx is updated, this update is delayed until there are no mutable references. Furthermore, you cannot just get a mutable reference to an Rx value, you must set it to an entirely new value.

The way it works is, there is an RxDAG which stores the entire dependency graph, and you can only get a reference to an Rx value from a shared reference to the graph. The Rxs update when you call RxDAG::recompute, which requires a mutable reference.

Furthermore, Rx closures must have a specific lifetime, because they may be recomputed. This lifetime is annotated 'c and the same lifetime is for every closure in an RxDAG. value directly, instead you use an associated function like [RxDAG::run_rx] to access it in a closure which can re-run whenever the dependency changes. You can create new Rxs from old ones.

Structs§

CRx
Index into the RxDAG which will give you a computed value.
DCRx
View a part of a CRx.
DVar
View and mutate a part of a Var.
RxDAG
The centralized structure which contains all your interconnected reactive values.
RxDAGSnapshot
Allows you to read from an RxDAG.
RxInput
Allows you to read from a slice of an RxDAG.
Var
Index into the RxDAG which will give you a variable.

Traits§

MutRxContext
Returns a slice of RxDAG you can write variables in.
RxContext
Returns a slice of RxDAG you can read nodes from.