pub struct DynObservable<T> { /* private fields */ }Expand description
A type-erased, cheaply-cloneable Observable.
Use this where a concrete observable type cannot appear — struct fields, collections of
heterogeneous reactive inputs, or component APIs that accept “a reactive T” regardless of
whether the caller has a Signal, Memo, Thunk, or a constant.
§Examples
use adaptite::{DynObservable, Observable, signal};
struct Label {
text: DynObservable<String>,
}
let static_label = Label {
text: DynObservable::constant(String::from("fixed")),
};
let dynamic = signal(String::from("live"));
let dynamic_label = Label {
text: dynamic.clone().into_dyn(),
};
assert_eq!(static_label.text.get(), "fixed");
assert_eq!(dynamic_label.text.get(), "live");
dynamic.set(String::from("updated"));
assert_eq!(dynamic_label.text.get(), "updated");Implementations§
Source§impl<T: 'static> DynObservable<T>
impl<T: 'static> DynObservable<T>
Trait Implementations§
Source§impl<T> Clone for DynObservable<T>
impl<T> Clone for DynObservable<T>
Source§impl<T> Debug for DynObservable<T>
impl<T> Debug for DynObservable<T>
Source§impl<T: 'static> Observable for DynObservable<T>
impl<T: 'static> Observable for DynObservable<T>
Source§fn into_dyn(self) -> DynObservable<T>
fn into_dyn(self) -> DynObservable<T>
Erases this observable’s concrete type behind a cheaply-cloneable handle.
Source§fn reactor(&self) -> Option<Reactor>
fn reactor(&self) -> Option<Reactor>
Returns the reactor this observable’s node belongs to, when it has one. Read more
Source§fn with<R>(&self, f: impl FnOnce(&T) -> R) -> R
fn with<R>(&self, f: impl FnOnce(&T) -> R) -> R
Runs
f with a shared reference to the current value, recording a dependency for the
currently running observer.Source§fn with_peek<R>(&self, f: impl FnOnce(&T) -> R) -> R
fn with_peek<R>(&self, f: impl FnOnce(&T) -> R) -> R
Runs
f with a shared reference to the current value without recording a dependency.Auto Trait Implementations§
impl<T> !RefUnwindSafe for DynObservable<T>
impl<T> !Send for DynObservable<T>
impl<T> !Sync for DynObservable<T>
impl<T> !UnwindSafe for DynObservable<T>
impl<T> Freeze for DynObservable<T>
impl<T> Unpin for DynObservable<T>
impl<T> UnsafeUnpin for DynObservable<T>where
Rc<dyn ErasedObservable<T>>: UnsafeUnpin,
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
Mutably borrows from an owned value. Read more