Trait WithValue

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

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

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

A variation of the With trait that provides a signposted “always-non-reactive” API. E.g. for StoredValue.

Required Associated Types§

type Value: ?Sized

The type of the value contained in the value.

Required Methods§

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

Applies the closure to the value, non-reactively, and returns the result, or None if the value has already been disposed.

Provided Methods§

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

Applies the closure to the value, non-reactively, and returns the result.

§Panics

Panics if you try to access a value that has 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.

Implementors§

§

impl<T> WithValue for T
where T: DefinedAt + ReadValue,

§

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