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§
Sourcetype Guard: WatcherGuard
type Guard: WatcherGuard
The guard type returned by the watch method that manages watcher lifecycle.
Required Methods§
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<A, B> Signal for Zip<A, B>
Implementation of the Signal trait for Zip.
impl<A, B> Signal for Zip<A, B>
Implementation of the Signal trait for Zip.
Source§type Output = (<A as Signal>::Output, <B as Signal>::Output)
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
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
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.
type Guard = (<A as Signal>::Guard, <B as Signal>::Guard)
Source§impl<C, F, Output> Signal for Map<C, F, Output>
impl<C, F, Output> Signal for Map<C, F, Output>
Source§impl<C, T> Signal for WithMetadata<C, T>
Implementation of signal for WithMetadata.
impl<C, T> Signal for WithMetadata<C, T>
Implementation of signal for WithMetadata.
This delegates the computation to the wrapped value but enriches the watcher notifications with the metadata.
Source§impl<S> Signal for StreamSignal<S>
impl<S> Signal for StreamSignal<S>
Source§fn get(&self) -> <StreamSignal<S> as Signal>::Output
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
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).
type Output = Option<<S as Stream>::Item>
type Guard = <Container<Option<<S as Stream>::Item>> as Signal>::Guard
Source§impl<T> Signal for FutureSignal<T>where
T: Clone + 'static,
impl<T> Signal for FutureSignal<T>where
T: Clone + 'static,
Source§fn get(&self) -> <FutureSignal<T> as Signal>::Output
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
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).