Skip to main content

UnwrapOrErr

Trait UnwrapOrErr 

Source
pub trait UnwrapOrErr<T> {
    // Required method
    fn unwrap_or_err(self) -> T;
}
Expand description

Returns the contained value from either variant of a Result<T, T>.

Unlike unwrap_or_default, the Err branch retains its value instead of constructing T::default().

Required Methods§

Source

fn unwrap_or_err(self) -> T

Returns the value carried by either result variant.

Both variants contain the same type, so neither branch needs conversion. The result is consumed without constructing a fallback value.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<T> UnwrapOrErr<T> for Result<T, T>