Skip to main content

With

Trait With 

pub trait With: DefinedAt {
    type Value: ?Sized;

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

    // Provided method
    fn with<U>(&self, fun: impl FnOnce(&Self::Value) -> U) -> U { ... }
}
Expand description

Give read-only access to a signal’s value by reference inside a closure, and subscribes the active reactive observer (an effect or computed) to changes in its value.

Required Associated Types§

type Value: ?Sized

The type of the value contained in the signal.

Required Methods§

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

Subscribes to the signal, applies the closure to the value, and returns the result, or None if the signal has already been disposed.

Provided Methods§

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

Subscribes to the signal, applies the closure to the value, and returns the result.

§Panics

Panics if you try to access a signal that has been disposed.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

§

impl<T, S> With for Model<T, S>
where S: Storage<ArcField<T>> + Storage<SignalTypes<T, S>> + Storage<T>,

§

type Value = T

§

fn try_with<O>( &self, f: impl FnOnce(&<Model<T, S> as With>::Value) -> O, ) -> Option<O>

§

impl<T, S> With for ReadModel<T, S>
where S: Storage<ArcField<T>> + Storage<SignalTypes<T, S>> + Storage<T>,

§

type Value = T

§

fn try_with<U>( &self, fun: impl FnOnce(&<ReadModel<T, S> as With>::Value) -> U, ) -> Option<U>

Implementors§

§

impl<T> With for T
where T: Read,

§

type Value = <<T as Read>::Value as Deref>::Target