pub trait DefensiveOption<T> {
// Required methods
fn defensive_map_or_else<U, D, F>(self, default: D, f: F) -> U
where D: FnOnce() -> U,
F: FnOnce(T) -> U;
fn defensive_ok_or_else<E, F>(self, err: F) -> Result<T, E>
where E: Debug,
F: FnOnce() -> E;
fn defensive_ok_or<E>(self, err: E) -> Result<T, E>
where E: Debug;
fn defensive_map<U, F>(self, f: F) -> Option<U>
where F: FnOnce(T) -> U;
}
Expand description
Subset of methods similar to Defensive
that can only work for a Option
.
Required Methods§
fn defensive_map_or_else<U, D, F>(self, default: D, f: F) -> U
fn defensive_map_or_else<U, D, F>(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.
fn defensive_ok_or_else<E, F>(self, err: F) -> Result<T, E>
fn defensive_ok_or_else<E, F>(self, err: F) -> Result<T, E>
Defensively transform this option to a result, mapping None
to the return value of an
error closure.
fn defensive_ok_or<E>(self, err: E) -> Result<T, E>where
E: Debug,
fn defensive_ok_or<E>(self, err: E) -> Result<T, E>where
E: Debug,
Defensively transform this option to a result, mapping None
to a default value.
fn defensive_map<U, F>(self, f: F) -> Option<U>where
F: FnOnce(T) -> U,
fn defensive_map<U, F>(self, f: F) -> Option<U>where
F: FnOnce(T) -> 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.