Trait frame_support::traits::DefensiveResult
source · 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§
sourcefn defensive_map_err<F, O: FnOnce(E) -> F>(self, o: O) -> Result<T, F>
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.
sourcefn defensive_map_or_else<U, D: FnOnce(E) -> U, F: FnOnce(T) -> U>(
self,
default: D,
f: F,
) -> U
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.
sourcefn defensive_ok(self) -> Option<T>
fn defensive_ok(self) -> Option<T>
Defensively transform this result into an option, discarding the Err
variant if it
happens, which should never happen.
sourcefn defensive_map<U, F: FnOnce(T) -> U>(self, f: F) -> Result<U, E>
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.