Skip to main content

Crate frust_reactive

Crate frust_reactive 

Source
Expand description

Reactive-programming substrate for Frust.

This crate owns the process-wide ReactiveRuntime: a background tokio runtime, a custom any_spawner executor that routes spawn to that runtime and spawn_local to a UI-thread local task queue, a swappable FrameWaker, and the root reactive Owner. It also re-exports the reactive_graph types the later programming-model tasks build on, and owns the process-wide deep-link source shells write platform deep links into (see push_deep_link/deep_links), the process-wide Android back-press source next to it (see push_back_press/back_presses and the handles_back flag), and the process-wide desktop menu-activation source beside those (see push_menu_event/menu_events). A process-wide signals-dirty flag (ReactiveRuntime::take_signals_dirty), tripped by TrackedScope’s dirty path, lets a shell ask synchronously and cheaply once per frame “did any tracked signal change since I last asked” — the reactive input to the mobile frame gate.

It is a leaf substrate: no winit, no vello/wgpu, no frust-core dependency. Shells own the wake-up wiring and call ReactiveRuntime::init (once, on the UI thread) and ReactiveRuntime::pump_local each frame.

Structs§

BackPresses
The app-facing back-press read surface (see the module docs). Obtained via back_presses (frust::back_presses() at the facade).
CanPopRegistration
Proof-of-registration token returned by set_can_pop_provider.
DeepLink
One delivered deep link: the raw platform-provided URL/location string (e.g. myapp://profile/42), unparsed — turning it into a route is the router layer’s job (the router/deep-link glue), not this crate’s.
DeepLinks
The app-facing deep-link read surface (see the module docs’ app_links semantics). Obtained via deep_links (frust::deep_links() at the facade).
MenuEvent
One delivered menu activation: the id the app gave the item in its MenuSpec (e.g. "file.open"), plus the process-wide sequence number of this activation (see the module docs). The id is passed through verbatim — mapping it to an action is app code’s job, not this crate’s.
MenuEvents
The app-facing menu-activation read surface. Obtained via menu_events (frust::menu_events() at the facade).
Owner
A reactive owner, which manages
ReactiveRuntime
The process-wide reactive runtime. Construct via ReactiveRuntime::init (once, on the UI thread) and reach later calls via ReactiveRuntime::get.
RwSignal
An arena-allocated signal that can be read from or written to.
TrackedScope
A reactive observer for a single frame-rebuild pass.
UseTask
The handle use_task returns: a read handle to the task’s AsyncValue<T> state plus a restart/refresh trigger.

Enums§

AsyncValue
The exhaustive state of an asynchronously-loaded value.

Functions§

back_presses
The current back-press read surface: the live BackPresses::count signal. Call from a tracked context (e.g. inside Component::build, via the facade’s BackHandler) to observe subsequent presses as they arrive.
clear_can_pop_provider
Force-clear the live can-pop provider unconditionally, restoring the polled handles_back fallback — a teardown/test hammer, NOT the handler cleanup path. A handler’s cleanup must go through its own CanPopRegistration::unregister so a stale registration can never clear a newer one (see the single-registrant invariant on set_can_pop_provider). Idempotent — safe with no provider registered, and it carries no thread constraint (clearing another thread’s empty slot is a harmless no-op).
deep_links
The current deep-link read surface: a snapshot of DeepLinks::initial plus the live DeepLinks::latest signal. Call from a tracked context (e.g. inside Component::build) to observe subsequent pushes as they arrive.
handles_back
Whether the framework wants to consume the next back press. A shell polls this to decide whether a back press should be routed into the app (true) or fall through to the platform / activity finish (false, the default until glue publishes otherwise — see the module docs).
menu_events
The current menu-activation read surface: the live MenuEvents::latest signal. Call from a tracked context (e.g. inside Component::build) to observe subsequent activations as they arrive.
on_cleanup
Registers a function to be run the next time the current owner is cleaned up.
provide_context
Provides a context value of type T to the current reactive Owner and all of its descendants. This can be accessed using use_context.
push_back_press
Deliver a platform back press into the process-wide source. Called by a shell (the Android back callback) on the UI thread; app code never calls this directly.
push_deep_link
Deliver a platform deep link (cold-start or warm) into the process-wide source. Called by a shell (the Android/iOS FFI glue) on the UI thread; app code never calls this directly.
push_menu_event
Deliver a native menu activation into the process-wide source. Called by a desktop shell’s per-frame menu pump on the UI thread; app code never calls this directly.
set_can_pop_provider
Register a live provider handles_back consults to answer “would a back press pop?” against the navigator’s CURRENT stack depth, not a rebuild-time snapshot. The facade’s BackHandler registers move || controller.can_pop(), so a press arriving between frames — after apply_ops published the new depth but before the next rebuild refreshed the polled flag — is decided correctly instead of falling through to activity finish (see the module docs’ timing section). A registered provider wins over set_handles_back’s flag; the returned CanPopRegistration token unregisters it scoped-safely.
set_handles_back
Publish whether the framework will consume the next back press (see the module docs’ handles_back section). The facade’s BackHandler calls this each rebuild with controller.can_pop(); a shell reads the answer via handles_back.
spawn_blocking
Runs a one-off, blocking CPU workload on the background runtime’s blocking thread pool, returning a JoinHandle to .await its result.
use_context
Extracts a context value of type T from the reactive system.
use_task
Runs a fetch, wiring a heavy-work idiom around it.

Type Aliases§

FrameWaker
A thread-safe, cheaply-cloneable “wake up and pump soon” callback. On desktop this is a winit EventLoopProxy send; on mobile (continuous frame loop) it is a no-op. It must be callable from any thread, since the executor fires it and background tasks may drive signal writes.
TaskError
The boxed error an AsyncValue::Error carries. Arc-wrapped so a clone of the state is cheap and the error is shareable across the tree.