Skip to main content

DynObservable

Struct DynObservable 

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

Source

pub fn constant(value: T) -> Self

Wraps a plain value as an observable that never changes and records no dependencies.

Useful for APIs that accept DynObservable<T> when the caller has a static value.

Trait Implementations§

Source§

impl<T> Clone for DynObservable<T>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<T> Debug for DynObservable<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: 'static> Observable for DynObservable<T>

Source§

type Item = T

The type of value this observable holds.
Source§

fn into_dyn(self) -> DynObservable<T>

Erases this observable’s concrete type behind a cheaply-cloneable handle.
Source§

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

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

Runs f with a shared reference to the current value without recording a dependency.
Source§

fn get(&self) -> Self::Item
where Self::Item: Clone,

Clones and returns the current value, recording a dependency.
Source§

fn peek(&self) -> Self::Item
where Self::Item: Clone,

Clones and returns the current value without recording a dependency.
Source§

fn map<U, F>(&self, f: F) -> Memo<U>
where Self: Clone + Sized + 'static, U: PartialEq + 'static, F: Fn(&Self::Item) -> U + 'static,

Derives a memo from this observable, cloning the receiver’s handle internally. Read more

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>
where Rc<dyn ErasedObservable<T>>: Freeze,

§

impl<T> Unpin for DynObservable<T>
where Rc<dyn ErasedObservable<T>>: Unpin,

§

impl<T> UnsafeUnpin for DynObservable<T>
where Rc<dyn ErasedObservable<T>>: UnsafeUnpin,

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<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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<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 = !

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

fn try_from(value: U) -> Result<T, !>

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

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more