pub trait UnwrapOrDefault {
    type Output;

    // Required method
    fn unwrap_or_default(self) -> Self::Output;
}
Expand description

Indicate that a type is a wrapper of a value and can be unwrapped into it or the default value.

Only available if the unwrap feature is enabled (enabled by default).

Unlike Unwrap, the trait UnwrapOrDefault indicates that when the wrapper does not contain a value, then it is able to create a default value instead of panic.

UnwrapOrDefault is implemented by default for four types:

Implement UnwrapOrDefault for your own wrapper types so that a Tuple containing your wrappers can be unwrap_or_default().

Required Associated Types§

source

type Output

Type of the contained value.

Required Methods§

source

fn unwrap_or_default(self) -> Self::Output

Get the contained value, or the default value if self does not contain a value.

§Example
use tuplez::*;

let tup = tuple!(Some(1), Err::<f32, &str>("failed"), Some("hello"));
assert_eq!(tup.unwrap_or_default(), tuple!(1, 0.0, "hello"));

Implementations on Foreign Types§

source§

impl<T: Default> UnwrapOrDefault for Option<T>

§

type Output = T

source§

fn unwrap_or_default(self) -> Self::Output

source§

impl<T: Default, E> UnwrapOrDefault for Result<T, E>

§

type Output = T

source§

fn unwrap_or_default(self) -> Self::Output

Implementors§

source§

impl UnwrapOrDefault for Unit

§

type Output = Unit

source§

impl<First, Other> UnwrapOrDefault for Tuple<First, Other>
where Other: TupleLike + UnwrapOrDefault, First: UnwrapOrDefault,

§

type Output = Tuple<<First as UnwrapOrDefault>::Output, <Other as UnwrapOrDefault>::Output>