Signal

Trait Signal 

Source
pub trait Signal: Clone + 'static {
    type Output: 'static;
    type Guard: WatcherGuard;

    // Required methods
    fn get(&self) -> Self::Output;
    fn watch(
        &self,
        watcher: impl Fn(Context<Self::Output>) + 'static,
    ) -> Self::Guard;
}
Expand description

The core trait for reactive system.

Types implementing Signal represent a computation that can produce a value and notify observers when that value changes.

Required Associated Types§

Source

type Output: 'static

The type of value produced by this computation.

Source

type Guard: WatcherGuard

The guard type returned by the watch method that manages watcher lifecycle.

Required Methods§

Source

fn get(&self) -> Self::Output

Execute the computation and return the current value.

Source

fn watch( &self, watcher: impl Fn(Context<Self::Output>) + 'static, ) -> Self::Guard

Register a watcher to be notified when the computed value changes.

Returns a guard that, when dropped, will unregister the watcher.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl Signal for &'static str

Source§

type Output = &'static str

Source§

type Guard = ()

Source§

fn get(&self) -> <&'static str as Signal>::Output

Source§

fn watch( &self, _watcher: impl Fn(Context<<&'static str as Signal>::Output>) + 'static, )

Source§

impl Signal for Cow<'static, str>

Source§

type Output = Cow<'static, str>

Source§

type Guard = ()

Source§

fn get(&self) -> <Cow<'static, str> as Signal>::Output

Source§

fn watch( &self, _watcher: impl Fn(Context<<Cow<'static, str> as Signal>::Output>) + 'static, )

Source§

impl Signal for bool

Source§

type Output = bool

Source§

type Guard = ()

Source§

fn get(&self) -> <bool as Signal>::Output

Source§

fn watch(&self, _watcher: impl Fn(Context<<bool as Signal>::Output>) + 'static)

Source§

impl Signal for char

Source§

type Output = char

Source§

type Guard = ()

Source§

fn get(&self) -> <char as Signal>::Output

Source§

fn watch(&self, _watcher: impl Fn(Context<<char as Signal>::Output>) + 'static)

Source§

impl Signal for f32

Source§

type Output = f32

Source§

type Guard = ()

Source§

fn get(&self) -> <f32 as Signal>::Output

Source§

fn watch(&self, _watcher: impl Fn(Context<<f32 as Signal>::Output>) + 'static)

Source§

impl Signal for f64

Source§

type Output = f64

Source§

type Guard = ()

Source§

fn get(&self) -> <f64 as Signal>::Output

Source§

fn watch(&self, _watcher: impl Fn(Context<<f64 as Signal>::Output>) + 'static)

Source§

impl Signal for i8

Source§

type Output = i8

Source§

type Guard = ()

Source§

fn get(&self) -> <i8 as Signal>::Output

Source§

fn watch(&self, _watcher: impl Fn(Context<<i8 as Signal>::Output>) + 'static)

Source§

impl Signal for i16

Source§

type Output = i16

Source§

type Guard = ()

Source§

fn get(&self) -> <i16 as Signal>::Output

Source§

fn watch(&self, _watcher: impl Fn(Context<<i16 as Signal>::Output>) + 'static)

Source§

impl Signal for i32

Source§

type Output = i32

Source§

type Guard = ()

Source§

fn get(&self) -> <i32 as Signal>::Output

Source§

fn watch(&self, _watcher: impl Fn(Context<<i32 as Signal>::Output>) + 'static)

Source§

impl Signal for i64

Source§

type Output = i64

Source§

type Guard = ()

Source§

fn get(&self) -> <i64 as Signal>::Output

Source§

fn watch(&self, _watcher: impl Fn(Context<<i64 as Signal>::Output>) + 'static)

Source§

impl Signal for u8

Source§

type Output = u8

Source§

type Guard = ()

Source§

fn get(&self) -> <u8 as Signal>::Output

Source§

fn watch(&self, _watcher: impl Fn(Context<<u8 as Signal>::Output>) + 'static)

Source§

impl Signal for u16

Source§

type Output = u16

Source§

type Guard = ()

Source§

fn get(&self) -> <u16 as Signal>::Output

Source§

fn watch(&self, _watcher: impl Fn(Context<<u16 as Signal>::Output>) + 'static)

Source§

impl Signal for u32

Source§

type Output = u32

Source§

type Guard = ()

Source§

fn get(&self) -> <u32 as Signal>::Output

Source§

fn watch(&self, _watcher: impl Fn(Context<<u32 as Signal>::Output>) + 'static)

Source§

impl Signal for u64

Source§

type Output = u64

Source§

type Guard = ()

Source§

fn get(&self) -> <u64 as Signal>::Output

Source§

fn watch(&self, _watcher: impl Fn(Context<<u64 as Signal>::Output>) + 'static)

Source§

impl Signal for String

Source§

type Output = String

Source§

type Guard = ()

Source§

fn get(&self) -> <String as Signal>::Output

Source§

fn watch( &self, _watcher: impl Fn(Context<<String as Signal>::Output>) + 'static, )

Source§

impl Signal for Duration

Source§

type Output = Duration

Source§

type Guard = ()

Source§

fn get(&self) -> <Duration as Signal>::Output

Source§

fn watch( &self, _watcher: impl Fn(Context<<Duration as Signal>::Output>) + 'static, )

Source§

impl<A, B> Signal for Zip<A, B>
where A: Signal, B: Signal, <A as Signal>::Output: Clone, <B as Signal>::Output: Clone,

Implementation of the Signal trait for Zip.

Source§

type Output = (<A as Signal>::Output, <B as Signal>::Output)

The output type of the zipped computation is a tuple of the outputs of the individual computations.

Source§

fn get(&self) -> <Zip<A, B> as Signal>::Output

Computes both values and returns them as a tuple.

§Returns

A tuple containing the results of computing a and b.

Source§

fn watch( &self, watcher: impl Fn(Context<<Zip<A, B> as Signal>::Output>) + 'static, ) -> <Zip<A, B> as Signal>::Guard

Adds a watcher to the zipped computation.

This method sets up watchers for both a and b such that when either one changes, the watcher for the Zip is notified with the new tuple.

§Parameters
  • watcher: The watcher to notify when either computation changes.
§Returns

A WatcherGuard that, when dropped, will remove the watchers from both computations.

Source§

type Guard = (<A as Signal>::Guard, <B as Signal>::Guard)

Source§

impl<C> Signal for Cached<C>
where C: Signal, <C as Signal>::Output: Clone,

Source§

type Output = <C as Signal>::Output

Source§

type Guard = <C as Signal>::Guard

Source§

fn get(&self) -> <Cached<C> as Signal>::Output

Source§

fn watch( &self, watcher: impl Fn(Context<<Cached<C> as Signal>::Output>) + 'static, ) -> <Cached<C> as Signal>::Guard

Source§

impl<C> Signal for Debug<C>
where C: Signal, <C as Signal>::Output: Debug,

Source§

type Output = <C as Signal>::Output

Source§

type Guard = Box<dyn WatcherGuard>

Source§

fn get(&self) -> <Debug<C> as Signal>::Output

Source§

fn watch( &self, watcher: impl Fn(Context<<C as Signal>::Output>) + 'static, ) -> <Debug<C> as Signal>::Guard

Source§

impl<C, F, Output> Signal for Map<C, F, Output>
where C: Signal, F: 'static + Clone + Fn(<C as Signal>::Output) -> Output, Output: 'static,

Source§

fn get(&self) -> Output

Computes the transformed value, using the cache when available.

Source§

fn watch( &self, watcher: impl Fn(Context<<Map<C, F, Output> as Signal>::Output>) + 'static, ) -> <Map<C, F, Output> as Signal>::Guard

Registers a watcher to be notified when the transformed value changes.

Source§

type Output = Output

Source§

type Guard = <C as Signal>::Guard

Source§

impl<C, T> Signal for WithMetadata<C, T>
where C: Signal, T: Clone + 'static,

Implementation of signal for WithMetadata.

This delegates the computation to the wrapped value but enriches the watcher notifications with the metadata.

Source§

fn get(&self) -> <WithMetadata<C, T> as Signal>::Output

Execute the underlying computation.

Source§

fn watch( &self, watcher: impl Fn(Context<<WithMetadata<C, T> as Signal>::Output>) + 'static, ) -> <WithMetadata<C, T> as Signal>::Guard

Register a watcher, enriching notifications with the metadata.

Source§

type Output = <C as Signal>::Output

Source§

type Guard = <C as Signal>::Guard

Source§

impl<K, V> Signal for BTreeMap<K, V>
where K: Clone + 'static, V: Clone + 'static,

Source§

type Output = BTreeMap<K, V>

Source§

type Guard = ()

Source§

fn get(&self) -> <BTreeMap<K, V> as Signal>::Output

Source§

fn watch( &self, _watcher: impl Fn(Context<<BTreeMap<K, V> as Signal>::Output>) + 'static, )

Source§

impl<S> Signal for Distinct<S>
where S: Signal, <S as Signal>::Output: PartialEq + Clone,

Source§

type Output = <S as Signal>::Output

Source§

type Guard = <S as Signal>::Guard

Source§

fn get(&self) -> <Distinct<S> as Signal>::Output

Source§

fn watch( &self, watcher: impl Fn(Context<<Distinct<S> as Signal>::Output>) + 'static, ) -> <Distinct<S> as Signal>::Guard

Source§

impl<S> Signal for StreamSignal<S>
where S: Stream + 'static, <S as Stream>::Item: Clone + 'static,

Source§

fn get(&self) -> <StreamSignal<S> as Signal>::Output

Returns the latest item produced by the underlying stream, if any.

Source§

fn watch( &self, watcher: impl Fn(Context<<StreamSignal<S> as Signal>::Output>) + 'static, ) -> <StreamSignal<S> as Signal>::Guard

Watches changes to the latest item (i.e., when the stream yields).

Source§

type Output = Option<<S as Stream>::Item>

Source§

type Guard = <Container<Option<<S as Stream>::Item>> as Signal>::Guard

Source§

impl<S, E> Signal for Debounce<S, E>
where S: Signal, <S as Signal>::Output: Clone + 'static, E: LocalExecutor + Clone + 'static,

Source§

type Output = <S as Signal>::Output

Source§

type Guard = WatcherManagerGuard<<S as Signal>::Output>

Source§

fn get(&self) -> <Debounce<S, E> as Signal>::Output

Source§

fn watch( &self, watcher: impl Fn(Context<<Debounce<S, E> as Signal>::Output>) + 'static, ) -> <Debounce<S, E> as Signal>::Guard

Source§

impl<S, E> Signal for Throttle<S, E>
where S: Signal, <S as Signal>::Output: Clone + 'static, E: LocalExecutor + Clone + 'static,

Source§

type Output = <S as Signal>::Output

Source§

type Guard = WatcherManagerGuard<<S as Signal>::Output>

Source§

fn get(&self) -> <Throttle<S, E> as Signal>::Output

Source§

fn watch( &self, watcher: impl Fn(Context<<Throttle<S, E> as Signal>::Output>) + 'static, ) -> <Throttle<S, E> as Signal>::Guard

Source§

impl<T> Signal for &'static [T]
where T: 'static,

Source§

type Output = &'static [T]

Source§

type Guard = ()

Source§

fn get(&self) -> <&'static [T] as Signal>::Output

Source§

fn watch( &self, _watcher: impl Fn(Context<<&'static [T] as Signal>::Output>) + 'static, )

Source§

impl<T> Signal for Option<T>
where T: Signal,

Source§

type Output = Option<<T as Signal>::Output>

Source§

type Guard = Option<<T as Signal>::Guard>

Source§

fn get(&self) -> <Option<T> as Signal>::Output

Source§

fn watch( &self, watcher: impl Fn(Context<<Option<T> as Signal>::Output>) + 'static, ) -> <Option<T> as Signal>::Guard

Source§

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

Source§

type Output = Vec<T>

Source§

type Guard = ()

Source§

fn get(&self) -> <Vec<T> as Signal>::Output

Source§

fn watch( &self, _watcher: impl Fn(Context<<Vec<T> as Signal>::Output>) + 'static, )

Source§

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

Source§

fn get(&self) -> <FutureSignal<T> as Signal>::Output

Returns Some(value) after the future resolves, else None.

Source§

fn watch( &self, watcher: impl Fn(Context<<FutureSignal<T> as Signal>::Output>) + 'static, ) -> <FutureSignal<T> as Signal>::Guard

Watches for completion and subsequent updates (if any).

Source§

type Output = Option<T>

Source§

type Guard = <Container<Option<T>> as Signal>::Guard

Source§

impl<T, E> Signal for Result<T, E>
where T: Signal, E: Signal,

Source§

type Output = Result<<T as Signal>::Output, <E as Signal>::Output>

Source§

type Guard = Result<<T as Signal>::Guard, <E as Signal>::Guard>

Source§

fn get(&self) -> <Result<T, E> as Signal>::Output

Source§

fn watch( &self, watcher: impl Fn(Context<<Result<T, E> as Signal>::Output>) + 'static, ) -> <Result<T, E> as Signal>::Guard

Implementors§

Source§

impl Signal for Str

Source§

impl<F, T> Signal for Lazy<F, T>
where F: 'static + Clone + Fn() -> T, T: Clone + 'static,

Source§

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

Source§

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

Source§

impl<T> Signal for Binding<T>
where T: 'static,

Source§

impl<T> Signal for Computed<T>
where T: 'static,

Implements Compute for Computed<T>.

This delegates to the internal boxed implementation.