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§
sourcefn defensive_map_or_else<U, D: FnOnce() -> U, F: FnOnce(T) -> U>(
self,
default: D,
f: F,
) -> U
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.
sourcefn defensive_ok_or_else<E: Debug, F: FnOnce() -> E>(
self,
err: F,
) -> Result<T, E>
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.
sourcefn defensive_ok_or<E: Debug>(self, err: E) -> Result<T, E>
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.
sourcefn defensive_map<U, F: FnOnce(T) -> U>(self, f: F) -> Option<U>
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.