Trait silkenweb::value::RefSignalOrValue

source ·
pub trait RefSignalOrValue<'a> {
    type Item: 'a;
    type Signal: Signal<Item = Self::Item> + 'a;
    type Map<'b: 'a, F: FnMut(Self::Item) -> R + 'b, R: RefSignalOrValue<'b, Item = R> + 'b>: RefSignalOrValue<'b, Item = R> + 'b;

    // Required methods
    fn map<'b, F, R>(self, callback: F) -> Self::Map<'b, F, R>
       where 'b: 'a,
             R: RefSignalOrValue<'b, Item = R> + 'b,
             F: FnMut(Self::Item) -> R + 'b;
    fn select<FVal, FSig, Data, Out>(
        self,
        fn_val: FVal,
        fn_sig: FSig,
        data: Data
    ) -> Out
       where FVal: FnOnce(Data, Self::Item) -> Out,
             FSig: FnOnce(Data, Self::Signal) -> Out,
             Self: Sized;
    fn select_spawn<FVal, FSig, Task, Exec>(
        self,
        fn_val: FVal,
        fn_sig: FSig,
        executor: &mut Exec
    )
       where FVal: FnOnce(&mut Exec, Self::Item),
             FSig: FnOnce(&mut Exec, Self::Signal) -> Task,
             Task: Future<Output = ()> + 'a,
             Exec: Executor;
}
Expand description

Abstract over a type that can be a value or a signal of an underlying type.

Required Associated Types§

source

type Item: 'a

The underlying type of the value or signal.

source

type Signal: Signal<Item = Self::Item> + 'a

The signal type. Use Always for value types.

source

type Map<'b: 'a, F: FnMut(Self::Item) -> R + 'b, R: RefSignalOrValue<'b, Item = R> + 'b>: RefSignalOrValue<'b, Item = R> + 'b

The return type for Self::map.

Map needs a separate lifetime 'b so that we can map from Self to something with a longer lifetime. For example, mapping &str to String.

Required Methods§

source

fn map<'b, F, R>(self, callback: F) -> Self::Map<'b, F, R>
where 'b: 'a, R: RefSignalOrValue<'b, Item = R> + 'b, F: FnMut(Self::Item) -> R + 'b,

Map a function over this signal/value to produce a new signal/value.

source

fn select<FVal, FSig, Data, Out>( self, fn_val: FVal, fn_sig: FSig, data: Data ) -> Out
where FVal: FnOnce(Data, Self::Item) -> Out, FSig: FnOnce(Data, Self::Signal) -> Out, Self: Sized,

Select a function based on whether this is a signal or value.

§Params
  • fn_val: The function to call if this is a value.
  • fn_sig: The function to call if this is a signal.
  • data: Some data for the function to consume. This is useful if either of the functions needs to consume some data.
source

fn select_spawn<FVal, FSig, Task, Exec>( self, fn_val: FVal, fn_sig: FSig, executor: &mut Exec )
where FVal: FnOnce(&mut Exec, Self::Item), FSig: FnOnce(&mut Exec, Self::Signal) -> Task, Task: Future<Output = ()> + 'a, Exec: Executor,

Select a function based on whether this is a signal or value.

For signal types, this will spawn the task produced by fn_sig with exec.

§Params
  • fn_val: The function to call if this is a value.
  • fn_sig: The function to call if this is a signal.
  • executor: An Executor to spawn the task from fn_sig.

Object Safety§

This trait is not object safe.

Implementors§

source§

impl<'a, T> RefSignalOrValue<'a> for Val<T>
where T: 'static,

§

type Item = T

§

type Map<'b: 'a, F: FnMut(<Val<T> as RefSignalOrValue<'a>>::Item) -> R + 'b, R: RefSignalOrValue<'b, Item = R> + 'b> = R

§

type Signal = Always<<Val<T> as RefSignalOrValue<'a>>::Item>

source§

impl<'a, T> RefSignalOrValue<'a> for T
where T: RefValue<'a> + 'a,

§

type Item = T

§

type Map<'b: 'a, F: FnMut(<T as RefSignalOrValue<'a>>::Item) -> R + 'b, R: RefSignalOrValue<'b, Item = R> + 'b> = R

§

type Signal = Always<<T as RefSignalOrValue<'a>>::Item>

source§

impl<T, S> RefSignalOrValue<'static> for Sig<S>
where T: 'static, S: Signal<Item = T> + 'static,

§

type Item = T

§

type Map<'b: 'static, F: FnMut(<Sig<S> as RefSignalOrValue<'static>>::Item) -> R + 'b, R: RefSignalOrValue<'b, Item = R> + 'b> = Sig<Map<S, F>>

§

type Signal = S