Trait Update

pub trait Update {
    type Value;

    // Required method
    fn try_maybe_update<U>(
        &self,
        fun: impl FnOnce(&mut Self::Value) -> (bool, U),
    ) -> Option<U>;

    // Provided methods
    fn update(&self, fun: impl FnOnce(&mut Self::Value)) { ... }
    fn maybe_update(&self, fun: impl FnOnce(&mut Self::Value) -> bool) { ... }
    fn try_update<U>(
        &self,
        fun: impl FnOnce(&mut Self::Value) -> U,
    ) -> Option<U> { ... }
}
Expand description

Updates the value of a signal by applying a function that updates it in place, notifying its subscribers that the value has changed.

Required Associated Typesยง

type Value

The type of the value contained in the signal.

Required Methodsยง

fn try_maybe_update<U>( &self, fun: impl FnOnce(&mut Self::Value) -> (bool, U), ) -> Option<U>

Updates the value of the signal, notifying subscribers if the update function returns (true, _), and returns the value returned by the update function, or None if the signal has already been disposed.

Provided Methodsยง

fn update(&self, fun: impl FnOnce(&mut Self::Value))

Updates the value of the signal and notifies subscribers.

fn maybe_update(&self, fun: impl FnOnce(&mut Self::Value) -> bool)

Updates the value of the signal, but only notifies subscribers if the function returns true.

fn try_update<U>(&self, fun: impl FnOnce(&mut Self::Value) -> U) -> Option<U>

Updates the value of the signal and notifies subscribers, returning the value that is returned by the update function, or None if the signal has already been disposed.

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ยง

ยง

impl<T, S> Update for Model<T, S>
where T: Clone, S: Storage<SignalTypes<T, S>> + Storage<ArcField<T>> + Storage<ArcWriteSignal<T>> + Storage<Box<dyn Fn(T) + Send + Sync>> + Storage<T>,

ยง

type Value = T

ยง

fn try_maybe_update<U>( &self, fun: impl FnOnce(&mut <Model<T, S> as Update>::Value) -> (bool, U), ) -> Option<U>

ยง

impl<T, S> Update for WriteModel<T, S>
where T: Clone, S: Storage<SignalTypes<T, S>> + Storage<ArcField<T>> + Storage<ArcWriteSignal<T>> + Storage<Box<dyn Fn(T) + Send + Sync>> + Storage<T>,

ยง

type Value = T

ยง

fn try_maybe_update<U>( &self, fun: impl FnOnce(&mut <WriteModel<T, S> as Update>::Value) -> (bool, U), ) -> Option<U>

Implementorsยง

ยง

impl<T> Update for T
where T: Write,

ยง

type Value = <T as Write>::Value