[][src]Crate moxie

moxie aims to empower everyone to build reliable and efficient human interfaces. This crate implements a lightweight & platform-agnostic UI runtime which powers a declarative style for creating interfaces and attempts to minimize latency and general overhead.


Memoization is the core tool which moxie provides to store data across Revisions and to minimize the incremental work performed when an update triggers the next Revision. Calls to the cache_* topological functions will perform memoization specific to the current position within the function call topology, as other topologically-nested functions do.

During run_once the cache and other runtime context is an environment value. Cache calls write to this storage to store results. At the end of run_once, this storage is garbage-collected, dropping values which were not referenced, marking them as live.

Memoized values are dropped in a deterministic manner when replaced or no longer referenced, modeling side-effectful lifecycle. Storing a type whose liveness represents the effect being "active" allows us to perform the effect when creating the stored value and to undo the effect when the stored value is Dropped.

Initializing a cached value at a particular callsite offers a simple API for incremental computations. Further, placing mutations in the initializer for a cache variable offers a path to minimizing the mutations or other side effects performed while describing the interface.





UI Runtime

A UI runtime is responsible for maintaining consistency between a program's desired output and the rendered output over time. The desired output is expected to change over time as a result of events from the "outside world." This might be due to user input or events caused by asynchronous tasks requested by a user.

The rendered output is usually modelled or expressed in terms of a visual or semantic hierarchy, or a tree. The relationships between elements in the tree partition the space in which the elements are rendered, subdividing it among their children. These relationships may or may not be concretely encoded within data structures or they may purely be the result of some side effects which occur in a particular order (e.g. mutating a display list for a GPU).

This process of performing the tasks to render the output is usually done in a loop, iterating either once per fixed interval (e.g. 60 frames per second or every 16.67 milliseconds) or when activated by the occurrence of events.



Integration points for the moxie runtime. Generally not called directly by applications.



A read-only pointer to the value of a state variable at a particular revision.


A Key offers access to a state variable. The key allows reads of the state variable through a snapshot taken when the Key was created. Writes are supported with Key::update and Key::set.



Memoizes init at this callsite, cloning a cached Output if it exists and Input is the same as when the stored value was created.


Root a state variable at this callsite, returning a Key to the state variable. Re-initializes the state variable if the capture arg changes.


Cache the return of the init function.


Load a value from a future, cloning it on subsequent revisions after it is first returned. Re-initializes the loading future if the capture argument changes from previous revisions.


Calls load_with, never re-initializes the loading future, and clones the returned value on each revision once the future has completed and returned.


Calls load_with but never re-initializes the loading future.


Load a value from the future returned by init whenever capture changes, returning the result of calling with with the loaded value. Cancels the running future after any revision during which this call was not made.


Runs the provided expression once per topo::CallId. The provided value will always be cloned on subsequent calls unless dropped from storage and reinitialized in a later Revision.


Memoizes expr once at the callsite. Runs with on every iteration.


Root a state variable at this callsite, returning a Key to the state variable.