Skip to main content

WithOptional

Trait WithOptional 

Source
pub trait WithOptional: DefinedAt {
    type Value: ?Sized;

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

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

An alternative With trait that works with Option<Withable> types.

Required Associated Types§

Source

type Value: ?Sized

The type of the value contained in the signal.

Required Methods§

Source

fn try_with<U>(&self, fun: impl FnOnce(Option<&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§

Source

fn with<U>(&self, fun: impl FnOnce(Option<&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", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl<T> WithOptional for Option<T>
where Option<T>: DefinedAt, T: With, <T as With>::Value: Sized,

Source§

type Value = <T as With>::Value

Source§

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

Implementors§