Skip to main content

Crate fusor

Crate fusor 

Source
Expand description

Reactive Rust for HTML script blocks, compiled by Cargo without a Rust DSL.

use fusor::{signal, derived, effect, batch};
let count = signal(0);
let doubled = derived({ let count = count.clone(); move || count.get() * 2 });
let subscription = effect(move || println!("{}", doubled.get()));
batch(|| { count.set(2); count.set(3); });
// Prints 0, then 6. Dropping the subscription stops it.
drop(subscription);

Re-exports§

pub use js::JsInputs;

Modules§

bind
What a bind attribute means for the Rust value it names. The HTML compiler picks the control from the markup; the bound value’s type decides how the control reads and edits it, so rustc checks the pairing. Reads track, so server rendering, hydration and browser effects all use the same methods.
coherence
Coherent async views and their loading status.
dom
Bind real DOM nodes to Rust closures. The browser creates the HTML DOM. A Scope owns its effects and event listeners. Drop it to unmount behavior.
js
Optional, component-local JavaScript modules and explicit Rust inputs.
prelude
The small set of types needed by a reactive application.

Macros§

bindings
Include an HTML module’s generated bindings in the ordinary Rust module declared by its script’s rust:module attribute. The argument is the entry registration (app) or a component registration from Cargo metadata.
template
Associate package-relative HTML with this ordinary Rust module.

Structs§

Cleanup
Run a callback exactly once when dropped. Combine with an owner registration or effect_with_cleanup to release external resources.
CleanupEffect
A reactive execution with a guard released before the next execution and on disposal. Destructors run without dependency tracking or registry borrows.
Derived
A lazy computation. Reads track its underlying signals in the consuming effect. It is deliberately not a cache: each get evaluates the function once.
Effect
Owns a subscription. Dropping it detaches every dependency.
Memo
A shared lazy cache of a pure computation over tracked signals and memos.
Owner
A unique lifetime owner. Commit starts registered work; drop disposes it. Handles are weak and cannot extend the lifetime. This is single-threaded.
OwnerHandle
Weak access to an owner’s lifecycle. Safe to retain after disposal.
Registration
Removing this registration unregisters the callback without invoking it.
Signal
Shared, single-threaded reactive state. Cloning shares the same value.

Enums§

ContextError
A context provider cannot be replaced or registered after disposal.

Traits§

ContextKey
A typed, namespaced key for a value supplied by a component or application. Distinct key types can provide the same value type without colliding.
FromInputs
The explicit input contract for compiler-resolved component tags.

Functions§

batch
Group synchronous writes into one notification per affected effect. Nested batches flush at the outer boundary. This is not a rollback transaction.
derived
effect
effect_with_cleanup
Track reads during setup, retaining its returned Rust value until replacement. Return a Cleanup for callback-based APIs or any existing RAII guard. Cleanup itself is untracked. A rerun that panics has already released its old guard; Rust’s ordinary unwind/abort behavior applies to the setup operation.
memo
Create a cached derivation using PartialEq to suppress unchanged results.
memo_with_eq
Create a cached derivation with an explicit equivalence relation. Equal values retain the old cache. |_, _| false publishes every recomputation.
signal
Create reactive state; reads inside an effect automatically subscribe to it.
untrack
Evaluate a closure without collecting dependencies in the current effect.

Derive Macros§

FromInputs
Generate a component’s named input struct and FromInputs implementation. Each field must be #[input] or #[local(init = expression)]. See fusor::FromInputs for the application-facing documentation.
JsInputs
Expose only marked Signal<T> fields to this component’s JavaScript module.