Struct frappe::Signal
[−]
[src]
pub struct Signal<T>(_);
Represents a discrete value that changes over time.
Signals are usually constructed by stream operations and can be read using the sample
or
sample_with
methods. They update lazily when someone reads them.
Methods
impl<T> Signal<T>
[src]
fn constant<V: Into<Rc<T>>>(val: V) -> Self
[src]
Creates a signal with constant value.
The value is assumed to be constant, so changing it while it's stored on the signal is a logic error and will cause unexpected results.
fn from_fn<F>(f: F) -> Self where
F: Fn() -> T + 'static,
[src]
F: Fn() -> T + 'static,
Creates a signal that samples it's values from an external source.
The closure is meant to sample a continuous value from the real world, so the signal value is assumed to be always changing.
fn has_changed(&self) -> bool
[src]
Checks if the signal has changed since the last time it was sampled.
fn sample_with<F, R>(&self, cb: F) -> R where
F: FnOnce(MaybeOwned<T>) -> R,
[src]
F: FnOnce(MaybeOwned<T>) -> R,
Sample by reference.
This is meant to be the most efficient way when cloning is undesirable, but it requires a callback to prevent outliving internal borrows.
impl<T: Clone> Signal<T>
[src]
impl<T: 'static> Signal<T>
[src]
fn map<F, R>(&self, f: F) -> Signal<R> where
F: Fn(MaybeOwned<T>) -> R + 'static,
R: 'static,
[src]
F: Fn(MaybeOwned<T>) -> R + 'static,
R: 'static,
Maps a signal with the provided function.
The closure is called only when the parent signal changes.
fn snapshot<S, F, R>(&self, trigger: &Stream<S>, f: F) -> Stream<R> where
F: Fn(MaybeOwned<T>, MaybeOwned<S>) -> R + 'static,
S: 'static,
R: 'static,
[src]
F: Fn(MaybeOwned<T>, MaybeOwned<S>) -> R + 'static,
S: 'static,
R: 'static,
Samples the value of this signal every time the trigger stream fires.
fn from_channel(initial: T, rx: Receiver<T>) -> Self
[src]
Stores the last value sent to a channel.
When sampled, the resulting signal consumes all the current values on the channel (using non-blocking operations) and returns the last value seen.
fn fold_channel<V, F>(initial: T, rx: Receiver<V>, f: F) -> Self where
F: Fn(T, V) -> T + 'static,
V: 'static,
[src]
F: Fn(T, V) -> T + 'static,
V: 'static,
Creates a signal that folds the values from a channel.
When sampled, the resulting signal consumes all the current values on the channel (using non-blocking operations) and folds them using the current signal value as the initial accumulator state.
impl<T: 'static> Signal<Signal<T>>
[src]
fn switch(&self) -> Signal<T>
[src]
Creates a new signal that samples the inner value of a nested signal.
Trait Implementations
impl<T: Debug> Debug for Signal<T>
[src]
impl<T: Default> Default for Signal<T>
[src]
impl<T> From<T> for Signal<T>
[src]
impl<T> From<Rc<T>> for Signal<T>
[src]
impl<T> Clone for Signal<T>
[src]
fn clone(&self) -> Self
[src]
Creates a copy of this signal that references the same value.
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more