Enum Binding

Source
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>.

Source

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>.

Source

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());
Source

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<T: Clone> Clone for Binding<T>

Implements the Clone contract for Binding<T>.

Source§

fn clone(&self) -> Self

Produces the clone required by the standard cloning contract.

1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl From<&String> for Binding<String>

Implements the From<&String> contract for Binding<String>.

Source§

fn from(value: &String) -> Self

Performs the documented infallible conversion.

Source§

impl From<&str> for Binding<String>

Implements the From<&str> contract for Binding<String>.

Source§

fn from(value: &str) -> Self

Performs the documented infallible conversion.

Source§

impl<T> From<Memo<T>> for Binding<T>

Implements the From<Memo<T>> contract for Binding<T>.

Source§

fn from(value: Memo<T>) -> Self

Performs the documented infallible conversion.

Source§

impl<T> From<Signal<T>> for Binding<T>

Implements the From<Signal<T>> contract for Binding<T>.

Source§

fn from(value: Signal<T>) -> Self

Performs the documented infallible conversion.

Source§

impl<T> From<State<T>> for Binding<T>

Implements the From<State<T>> contract for Binding<T>.

Source§

fn from(value: State<T>) -> Self

Performs the documented infallible conversion.

Source§

impl<T> From<T> for Binding<T>

Implements the From<T> contract for Binding<T>.

Source§

fn from(value: T) -> Self

Performs the documented infallible conversion.

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<!> for T

Source§

fn from(t: !) -> T

Converts to this type from the input type.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<A> IntoClickAction<A> for A
where A: Clone + 'static,

Source§

fn into_click_action(self) -> ClickAction<A>

Implements the into_click_action helper used by this module.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> Props for T
where T: Clone + 'static,