Module silkenweb::value

source ·
Expand description

Abstract over the signal/value-ness of types.

This allows you to write a single function that works for both signals and values.

§Example

struct Exec;

impl Executor for Exec {
    fn spawn(&mut self, future: impl Future<Output = ()> + 'static) {
        // This is a stub `Executor` for brevity. In real code, it should
        // run the future.
    }
}

fn increment_and_print(x: impl SignalOrValue<Item = i32>) {
    x.map(|x| x + 1).select_spawn(
        |_exec, x| println!("{x}"),
        |exec, x| {
            x.for_each(|x| {
                println!("{x}");
                async {}
            })
        },
        &mut Exec,
    );
}

let x_signal = Mutable::new(0);
let x_value = 0;

increment_and_print(x_value);
increment_and_print(Sig(x_signal.signal()));

Structs§

  • Newtype wrapper to mark this type as a signal.
  • Newtype wrapper to mark this type as a static value.

Traits§