[][src]Struct frappe::signal::Signal

pub struct Signal<T>(_);

Represents a value that changes over time.

Methods

impl<T> Signal<T>[src]

pub fn constant(val: T) -> Self where
    T: Clone + Send + Sync + 'static, 
[src]

Creates a signal with constant value.

pub fn from_fn<F>(f: F) -> Self where
    F: Fn() -> T + Send + Sync + 'static, 
[src]

Creates a signal that samples it's values from an external source.

pub fn sample(&self) -> T[src]

Samples the value of the signal.

The action of sampling pulls the value through the signal chain until it finds it's source, clones it if necessary, and then transforms it into the result value.

pub fn map<F, R>(&self, f: F) -> Signal<R> where
    F: Fn(T) -> R + Send + Sync + 'static,
    T: 'static, 
[src]

Maps a signal using the provided function.

The map operation applies the function to the signal value every time it's sampled.

pub fn fold<A, F>(&self, initial: A, f: F) -> Signal<A> where
    F: Fn(A, T) -> A + Send + Sync + 'static,
    T: 'static,
    A: Clone + Send + Sync + 'static, 
[src]

Folds a signal using the provided function.

The fold operation applies a Fn(A, T) -> A function on the signal every time it's sampled, where A is the current accumulator value and T is the value of the input signal. The result of this call is stored on the accumulator and returned as the output signal's value.

pub fn snapshot<S, F, R>(&self, trigger: &Stream<S>, f: F) -> Stream<R> where
    F: Fn(T, MaybeOwned<S>) -> R + Send + Sync + 'static,
    T: 'static,
    S: 'static,
    R: 'static, 
[src]

Samples the value of this signal every time the trigger stream fires.

pub fn from_channel(initial: T, rx: Receiver<T>) -> Self where
    T: Clone + Send + Sync + 'static, 
[src]

Stores the last value sent to a channel.

When sampled, the resulting signal consumes all the current values on the channel (using try_recv) and returns the last value seen.

pub fn fold_channel<V, F>(initial: T, rx: Receiver<V>, f: F) -> Self where
    F: Fn(T, V) -> T + Send + Sync + 'static,
    T: Clone + Send + Sync + 'static,
    V: Send + 'static, 
[src]

Creates a signal that folds the values from a channel.

When sampled, the resulting signal consumes all the current values on the channel (using try_recv) and folds them using the current signal value as the initial accumulator state.

pub fn cyclic<F>(definition: F) -> Self where
    F: FnOnce(&Signal<T>) -> Signal<T>,
    T: 'static, 
[src]

Creates a signal with a cyclic definition.

This allows creating a self-referential Signal definition. The closure receives a forward declaration of a signal that must be used to construct the final Signal. Then this previous forward-declaration is replaced with the value returned by the closure.

Sampling the forward-declared signal will cause a panic.

impl<T: 'static> Signal<Signal<T>>[src]

pub fn switch(&self) -> Signal<T>[src]

Creates a new signal that samples the inner value of a nested signal.

Trait Implementations

impl<T: Default + 'static> Default for Signal<T>[src]

fn default() -> Self[src]

Creates a constant signal with T's default value.

impl<T: Clone + Send + Sync + 'static> From<T> for Signal<T>[src]

fn from(val: T) -> Self[src]

Creates a constant signal from T.

impl<T> Clone for Signal<T>[src]

fn clone(&self) -> Self[src]

Creates a new signal that references the same value.

fn clone_from(&mut self, source: &Self)
1.0.0
[src]

Performs copy-assignment from source. Read more

impl<T: Display> Display for Signal<T>[src]

fn fmt(&self, f: &mut Formatter) -> Result[src]

Samples the signal and formats the value.

impl<T> Debug for Signal<T>[src]

Auto Trait Implementations

impl<T> Send for Signal<T>

impl<T> Sync for Signal<T>

Blanket Implementations

impl<T, U> Into for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T> From for T[src]

impl<T, U> TryFrom for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T> Borrow for T where
    T: ?Sized
[src]

impl<T> BorrowMut for T where
    T: ?Sized
[src]

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Erased for T