referrerpolicy=no-referrer-when-downgrade

Trait frame_support::traits::DefensiveOption

source ·
pub trait DefensiveOption<T> {
    // Required methods
    fn defensive_map_or_else<U, D: FnOnce() -> U, F: FnOnce(T) -> U>(
        self,
        default: D,
        f: F,
    ) -> U;
    fn defensive_ok_or_else<E: Debug, F: FnOnce() -> E>(
        self,
        err: F,
    ) -> Result<T, E>;
    fn defensive_ok_or<E: Debug>(self, err: E) -> Result<T, E>;
    fn defensive_map<U, F: FnOnce(T) -> U>(self, f: F) -> Option<U>;
}
Expand description

Subset of methods similar to Defensive that can only work for a Option.

Required Methods§

source

fn defensive_map_or_else<U, D: FnOnce() -> U, F: FnOnce(T) -> U>( self, default: D, f: F, ) -> U

Potentially map and unpack the value to something else (U), or call the default callback if None, which should never happen.

source

fn defensive_ok_or_else<E: Debug, F: FnOnce() -> E>( self, err: F, ) -> Result<T, E>

Defensively transform this option to a result, mapping None to the return value of an error closure.

source

fn defensive_ok_or<E: Debug>(self, err: E) -> Result<T, E>

Defensively transform this option to a result, mapping None to a default value.

source

fn defensive_map<U, F: FnOnce(T) -> U>(self, f: F) -> Option<U>

Exactly the same as map, but it prints the appropriate warnings if the value being mapped is None.

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl<T> DefensiveOption<T> for Option<T>

source§

fn defensive_map_or_else<U, D: FnOnce() -> U, F: FnOnce(T) -> U>( self, default: D, f: F, ) -> U

source§

fn defensive_ok_or_else<E: Debug, F: FnOnce() -> E>( self, err: F, ) -> Result<T, E>

source§

fn defensive_ok_or<E: Debug>(self, err: E) -> Result<T, E>

source§

fn defensive_map<U, F: FnOnce(T) -> U>(self, f: F) -> Option<U>

Implementors§