FerroUI/ docs

Search guides, controls, Rust APIs, and XAML.

    GitHub ↗

    ObservableAsPropertyHelper

    struct · ferroui-reactiveui · v0.5.0

    struct ObservableAsPropertyHelper<T: 'static>
    

    Backs a read-only output property with an observable: the property reports each new value through the callbacks it was created with, so that its owner raises its own change notifications (ObservableAsPropertyHelper<T>).

    It is normally made by to_property, whose callbacks raise the owner's notifications for the named property; it can also be made directly with callbacks of one's own. A view model stores it (in a OnceCell or a RefCell<Option<..>>) and reads value in its getter.

    Values equal to the previous one are skipped. Without a scheduler, or with the immediate one, each value is delivered at once; a value produced while another is being delivered waits for that delivery to end, so the callbacks never nest.

    The helper is a shared handle: its clones are the same helper.

    View source

    Members

    new

    fn new(observable: Rc<dyn IObservable<T>>, on_changed: impl Fn(T) -> () + 'static) -> Self
    where T: Default
    

    A helper that follows observable from the default value of T, running on_changed with each new value (ObservableAsPropertyHelper(IObservable<T?>, Action<T?>)).

    Source

    with_initial_value

    fn with_initial_value(observable: Rc<dyn IObservable<T>>, on_changed: impl Fn(T) -> () + 'static, initial_value: T) -> Self
    

    A helper that starts from initial_value (ObservableAsPropertyHelper(IObservable<T?>, Action<T?>, T?)).

    Source

    with_initial_value_on

    fn with_initial_value_on(observable: Rc<dyn IObservable<T>>, on_changed: impl Fn(T) -> () + 'static, initial_value: T, scheduler: Option<Rc<dyn IScheduler>>) -> Self
    

    A helper that starts from initial_value and delivers its values on scheduler (ObservableAsPropertyHelper(IObservable<T?>, Action<T?>, T?, ISequencer?)).

    Source

    with_initial_value_deferred

    fn with_initial_value_deferred(observable: Rc<dyn IObservable<T>>, on_changed: impl Fn(T) -> () + 'static, initial_value: T, defer_subscription: bool) -> Self
    

    A helper that starts from initial_value and, when defer_subscription is set, subscribes to observable on the first read of value (ObservableAsPropertyHelper(IObservable<T?>, Action<T?>, T?, bool)).

    Source

    with_changing

    fn with_changing(observable: Rc<dyn IObservable<T>>, on_changed: impl Fn(T) -> () + 'static, on_changing: impl Fn(T) -> () + 'static) -> Self
    where T: Default
    

    A helper with a callback run before each new value is stored, as well as the one run after (ObservableAsPropertyHelper(IObservable<T?>, Action<T?>, Action<T?>?)).

    Source

    with_options

    fn with_options(observable: Rc<dyn IObservable<T>>, on_changed: impl Fn(T) -> () + 'static, on_changing: Option<Rc<dyn Fn(T) -> ()>>, initial_value: ObservableAsPropertyInitialValue<T>, defer_subscription: bool, scheduler: Option<Rc<dyn IScheduler>>) -> Self
    

    The helper with every option: on_changing runs before each new value is stored and on_changed after; initial_value is a value or a factory; defer_subscription delays the subscription to the first read of value; scheduler delivers the values (the other constructors of upstream, which this one covers).

    Source

    create

    fn create<O: 'static>(observable: Rc<dyn IObservable<T>>, owner: &Rc<O>, on_changed: impl Fn(&Rc<O>, T) -> () + 'static, on_changing: Option<Rc<dyn Fn(&Rc<O>, T) -> ()>>, initial_value: ObservableAsPropertyInitialValue<T>, defer_subscription: bool, scheduler: Option<Rc<dyn IScheduler>>) -> Self
    

    A helper whose callbacks take its owner, which the helper holds weakly: once the owner is dropped, the callbacks are not run (Create(IObservable<T?>, object, Action<object?, T?>, Action<object?, T?>?, T?, bool, ISequencer?), the factory that ToProperty uses).

    Source

    default_with_initial_value

    fn default_with_initial_value(initial_value: T) -> Self
    

    A helper that holds initial_value and never changes (Default(T?)).

    Source

    default_with_initial_value_on

    fn default_with_initial_value_on(initial_value: T, scheduler: Option<Rc<dyn IScheduler>>) -> Self
    

    A helper that holds initial_value, delivered on scheduler, and never changes (Default(T?, ISequencer?)).

    Source

    value

    fn value(self: &Self) -> T
    

    The last value of the property; a deferred helper subscribes on its first read (Value).

    Source

    is_subscribed

    fn is_subscribed(self: &Self) -> bool
    

    Whether the helper has subscribed to its source (IsSubscribed).

    Source

    thrown_exceptions

    fn thrown_exceptions(self: &Self) -> Rc<dyn IObservable<ObservableError>>
    

    The errors of the source (ThrownExceptions). While it has no observer, an error goes to RxState::default_exception_handler.

    Source

    Trait implementations

    • Send
    • Sync
    • Freeze
    • UnsafeUnpin
    • Unpin
    • UnwindSafe
    • RefUnwindSafe
    • Borrow<T>
    • BorrowMut<T>
    • CloneToUninit
    • Into<U>
    • From<T>
    • TryInto<U>
    • TryFrom<U>
    • Any
    • ToOwned
    • Clone
    • Default
    • IDisposable

    Availability

    Extracted for aarch64-apple-darwin. Cargo features are listed in the crate index.