pub enum Binding<T> {
Static(T),
Signal(Signal<T>),
Memo(Memo<T>),
}Expand description
Bindable widget prop: static value, Signal, or Memo.
Unifies disabled(true), disabled(signal), and disabled(memo) without separate DSL methods.
Cloning a static binding clones T; cloning reactive variants aliases their
existing Rc-backed source. Reads always return an owned value and memos are
evaluated on every read. Signal-backed and transitively reactive memo reads
register the innermost retained Build/Layout/Paint consumer; static values do
not create a dependency. Conditional memo reads observe only sources reached
by the executed branch. The surrounding callback publishes that set only on
success and replaces its previous set atomically. Because the reactive
variants are Rc-backed, a binding is UI-thread-local and neither Send nor
Sync. Subscriptions belong to the mounted consumer rather than the binding:
unmounting removes them while independently owned bindings remain usable.
§Examples
use ailloli_ui_runtime::component::Binding;
let binding: Binding<String> = "label".into();
assert_eq!(binding.read(), "label");
assert!(!binding.is_signal());Variants§
Static(T)
Owned non-reactive value with constant revision zero.
Signal(Signal<T>)
Aliased mutable signal.
Memo(Memo<T>)
Lazy derived value, possibly carrying a source revision.
Implementations§
Source§impl<T: Clone> Binding<T>
Provides the operations defined for Binding<T>.
impl<T: Clone> Binding<T>
Provides the operations defined for Binding<T>.
Sourcepub fn read(&self) -> T
pub fn read(&self) -> T
Returns an owned current value.
Static and signal variants clone T; a memo evaluates its stored
computation. Reactive variants are observed by the innermost retained
build, layout, or paint callback; reads elsewhere are passive. A failed
surrounding callback does not publish its staged dependency set.
§Panics
Panics if cloning T panics, a signal value is already mutably borrowed
through another alias, or the stored memo computation panics.
§Examples
use ailloli_ui_runtime::component::{Binding, Memo};
let static_value = Binding::Static(3);
let derived = Binding::Memo(Memo::new(|| 4));
assert_eq!((static_value.read(), derived.read()), (3, 4));Source§impl<T> Binding<T>
Provides the operations defined for Binding<T>.
impl<T> Binding<T>
Provides the operations defined for Binding<T>.
Sourcepub fn is_signal(&self) -> bool
pub fn is_signal(&self) -> bool
Returns true only for the direct Binding::Signal variant.
A memo derived from a signal still returns false; inspect
Self::revision when the distinction of interest is reactivity.
§Examples
use std::{cell::RefCell, rc::Rc};
use ailloli_ui_runtime::component::{Binding, Signal};
let signal = Signal::new(Rc::new(RefCell::new(1)), Rc::new(|| {}));
let binding: Binding<i32> = signal.into();
assert!(binding.is_signal());Sourcepub fn revision(&self) -> u64
pub fn revision(&self) -> u64
Observed revision of the reactive source used by retained caches.
Static bindings and opaque memos without a reactive source remain at
revision zero. Memos derived from a Signal preserve its revision.
Revisions reserve zero for pristine/opaque sources and wrap from
u64::MAX to one. Signal and derived-memo revision reads observe their
source unless the runtime explicitly installs an untracked admin scope.
§Examples
use std::{cell::RefCell, rc::Rc};
use ailloli_ui_runtime::component::{Binding, Signal};
let signal = Signal::new(Rc::new(RefCell::new(1)), Rc::new(|| {}));
let memo_binding: Binding<i32> = signal.map(|value| value + 1).into();
assert_eq!(memo_binding.revision(), 0);
signal.set(2);
assert_eq!(memo_binding.revision(), 1);Trait Implementations§
Source§impl From<&String> for Binding<String>
Implements the From<&String> contract for Binding<String>.
impl From<&String> for Binding<String>
Implements the From<&String> contract for Binding<String>.
Source§impl<T> From<Signal<T>> for Binding<T>
Implements the From<Signal<T>> contract for Binding<T>.
impl<T> From<Signal<T>> for Binding<T>
Implements the From<Signal<T>> contract for Binding<T>.
Auto Trait Implementations§
impl<T> Freeze for Binding<T>where
T: Freeze,
impl<T> !RefUnwindSafe for Binding<T>
impl<T> !Send for Binding<T>
impl<T> !Sync for Binding<T>
impl<T> Unpin for Binding<T>where
T: Unpin,
impl<T> !UnwindSafe for Binding<T>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<A> IntoClickAction<A> for Awhere
A: Clone + 'static,
impl<A> IntoClickAction<A> for Awhere
A: Clone + 'static,
Source§fn into_click_action(self) -> ClickAction<A>
fn into_click_action(self) -> ClickAction<A>
Implements the into_click_action helper used by this module.