Trait tuplez::UnwrapOrDefault
source · 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:
Option<T>Result<T, E>UnitTuple<T0, T1, ... Tn>if all typesT0,T1, …TnimplementUnwrapOrDefault.
Implement UnwrapOrDefault for your own wrapper types so that a Tuple containing your wrappers can
be unwrap_or_default().
Required Associated Types§
Required Methods§
sourcefn unwrap_or_default(self) -> Self::Output
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"));