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
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>
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))
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)
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>
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.