pub trait DefensiveResult<T, E> {
    // Required methods
    fn defensive_map_err<F, O: FnOnce(E) -> F>(self, o: O) -> Result<T, F>;
    fn defensive_map_or_else<U, D: FnOnce(E) -> U, F: FnOnce(T) -> U>(
        self,
        default: D,
        f: F,
    ) -> U;
    fn defensive_ok(self) -> Option<T>;
    fn defensive_map<U, F: FnOnce(T) -> U>(self, f: F) -> Result<U, E>;
}
Expand description

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

Required Methods§

source

fn defensive_map_err<F, O: FnOnce(E) -> F>(self, o: O) -> Result<T, F>

Defensively map the error into another return type, but you are really sure that this conversion should never be needed.

source

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

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

source

fn defensive_ok(self) -> Option<T>

Defensively transform this result into an option, discarding the Err variant if it happens, which should never happen.

source

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

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

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl<T, E: Debug> DefensiveResult<T, E> for Result<T, E>

source§

fn defensive_map_err<F, O: FnOnce(E) -> F>(self, o: O) -> Result<T, F>

source§

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

source§

fn defensive_ok(self) -> Option<T>

source§

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

Implementors§