Signal

Trait Signal 

Source
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§

Source

type Output: 'static

The type of value produced by this computation.

Source

type Guard: WatcherGuard

The guard type returned by the watch method that manages watcher lifecycle.

Required Methods§

Source

fn get(&self) -> Self::Output

Execute the computation and return the current value.

Source

fn watch( &self, watcher: impl Fn(Context<Self::Output>) + 'static, ) -> Self::Guard

Register a watcher to be notified when the computed value changes.

Returns a guard that, when dropped, will unregister the watcher.

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 Signal for &'static str

Source§

type Output = &'static str

Source§

type Guard = ()

Source§

fn get(&self) -> Self::Output

Source§

fn watch(&self, _watcher: impl Fn(Context<Self::Output>) + 'static)

Source§

impl Signal for Cow<'static, str>

Source§

type Output = Cow<'static, str>

Source§

type Guard = ()

Source§

fn get(&self) -> Self::Output

Source§

fn watch(&self, _watcher: impl Fn(Context<Self::Output>) + 'static)

Source§

impl Signal for bool

Source§

type Output = bool

Source§

type Guard = ()

Source§

fn get(&self) -> Self::Output

Source§

fn watch(&self, _watcher: impl Fn(Context<Self::Output>) + 'static)

Source§

impl Signal for char

Source§

type Output = char

Source§

type Guard = ()

Source§

fn get(&self) -> Self::Output

Source§

fn watch(&self, _watcher: impl Fn(Context<Self::Output>) + 'static)

Source§

impl Signal for f32

Source§

type Output = f32

Source§

type Guard = ()

Source§

fn get(&self) -> Self::Output

Source§

fn watch(&self, _watcher: impl Fn(Context<Self::Output>) + 'static)

Source§

impl Signal for f64

Source§

type Output = f64

Source§

type Guard = ()

Source§

fn get(&self) -> Self::Output

Source§

fn watch(&self, _watcher: impl Fn(Context<Self::Output>) + 'static)

Source§

impl Signal for i8

Source§

type Output = i8

Source§

type Guard = ()

Source§

fn get(&self) -> Self::Output

Source§

fn watch(&self, _watcher: impl Fn(Context<Self::Output>) + 'static)

Source§

impl Signal for i16

Source§

type Output = i16

Source§

type Guard = ()

Source§

fn get(&self) -> Self::Output

Source§

fn watch(&self, _watcher: impl Fn(Context<Self::Output>) + 'static)

Source§

impl Signal for i32

Source§

type Output = i32

Source§

type Guard = ()

Source§

fn get(&self) -> Self::Output

Source§

fn watch(&self, _watcher: impl Fn(Context<Self::Output>) + 'static)

Source§

impl Signal for i64

Source§

type Output = i64

Source§

type Guard = ()

Source§

fn get(&self) -> Self::Output

Source§

fn watch(&self, _watcher: impl Fn(Context<Self::Output>) + 'static)

Source§

impl Signal for u8

Source§

type Output = u8

Source§

type Guard = ()

Source§

fn get(&self) -> Self::Output

Source§

fn watch(&self, _watcher: impl Fn(Context<Self::Output>) + 'static)

Source§

impl Signal for u16

Source§

type Output = u16

Source§

type Guard = ()

Source§

fn get(&self) -> Self::Output

Source§

fn watch(&self, _watcher: impl Fn(Context<Self::Output>) + 'static)

Source§

impl Signal for u32

Source§

type Output = u32

Source§

type Guard = ()

Source§

fn get(&self) -> Self::Output

Source§

fn watch(&self, _watcher: impl Fn(Context<Self::Output>) + 'static)

Source§

impl Signal for u64

Source§

type Output = u64

Source§

type Guard = ()

Source§

fn get(&self) -> Self::Output

Source§

fn watch(&self, _watcher: impl Fn(Context<Self::Output>) + 'static)

Source§

impl Signal for String

Source§

type Output = String

Source§

type Guard = ()

Source§

fn get(&self) -> Self::Output

Source§

fn watch(&self, _watcher: impl Fn(Context<Self::Output>) + 'static)

Source§

impl Signal for Duration

Source§

type Output = Duration

Source§

type Guard = ()

Source§

fn get(&self) -> Self::Output

Source§

fn watch(&self, _watcher: impl Fn(Context<Self::Output>) + 'static)

Source§

impl<K: Clone + 'static, V: Clone + 'static> Signal for BTreeMap<K, V>

Source§

type Output = BTreeMap<K, V>

Source§

type Guard = ()

Source§

fn get(&self) -> Self::Output

Source§

fn watch(&self, _watcher: impl Fn(Context<Self::Output>) + 'static)

Source§

impl<T: 'static> Signal for &'static [T]

Source§

type Output = &'static [T]

Source§

type Guard = ()

Source§

fn get(&self) -> Self::Output

Source§

fn watch(&self, _watcher: impl Fn(Context<Self::Output>) + 'static)

Source§

impl<T: Clone + 'static> Signal for Option<T>

Source§

type Output = Option<T>

Source§

type Guard = ()

Source§

fn get(&self) -> Self::Output

Source§

fn watch(&self, _watcher: impl Fn(Context<Self::Output>) + 'static)

Source§

impl<T: Clone + 'static> Signal for Vec<T>

Source§

type Output = Vec<T>

Source§

type Guard = ()

Source§

fn get(&self) -> Self::Output

Source§

fn watch(&self, _watcher: impl Fn(Context<Self::Output>) + 'static)

Source§

impl<T: Clone + 'static, E: Clone + 'static> Signal for Result<T, E>

Source§

type Output = Result<T, E>

Source§

type Guard = ()

Source§

fn get(&self) -> Self::Output

Source§

fn watch(&self, _watcher: impl Fn(Context<Self::Output>) + 'static)

Implementors§