Signal<T> is a readable and writable reactive value. Signals are Clone, which makes them convenient to pass into closures and store in structs. Every adapter implements the same trait, and the blanket SignalExt extension adds convenience methods with zero per-adapter overhead.
Import: use quoin_core::prelude::*;
Signal methods
Section titled “Signal methods”| Method | Signature | Description |
|---|---|---|
get |
fn get(&self) -> T |
Returns a clone of the current value. |
with |
fn with<R>(&self, f: impl FnOnce(&T) -> R) -> R |
Borrows the value without cloning. |
set |
fn set(&self, value: T) |
Writes the value and requests an update. |
set_if_eq |
fn set_if_eq(&self, value: T) -> bool where T: PartialEq |
Writes only when the value differs; returns true when written. Single-lock implementations override this for a cheaper compare-and-write. |
update |
fn update(&self, f: impl FnOnce(&mut T)) |
Mutates the value in place. |
SignalExt methods
Section titled “SignalExt methods”| Method | Signature | Default behavior |
|---|---|---|
set_eq |
fn set_eq(&self, value: T) -> bool where T: PartialEq |
Delegates to set_if_eq; skipping equal writes removes wasted re-render requests on pull-based adapters. |
replace |
fn replace(&self, value: T) -> T |
Sets the value and returns the previous one. |
take |
fn take(&self) -> T where T: Default |
Replaces the value with T::default() and returns the old value. |
map |
fn map<U, F>(&self, f: F) -> Derived<Self, T, U, F> |
Sugar for derived(self, f) — a read-only computed view. |
Example
Section titled “Example”let signal = cx.create_signal(42u32);assert_eq!(signal.get(), 42);signal.with(|v| println!("{v}")); // borrow without cloningsignal.set(100);signal.update(|v| *v += 1);assert_eq!(signal.get(), 101);
signal.set_eq(101); // false — unchanged, no update requestedlet old = signal.replace(7); // old == 101let taken = signal.take(); // taken == 7, signal now 0Next steps
Section titled “Next steps”-
Derived Signals & MemosComputed views, memoization, and zipped signals.
-
Reactive ContextWhere signals are created and how update requests flow.
