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
.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.