Trait tuplez::Unwrap

source ·
pub trait Unwrap {
    type Output;

    // Required methods
    fn unwrap(self) -> Self::Output;
    fn has_value(&self) -> bool;
}
Expand description

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

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

Unwrap is implemented by default for four types:

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

Required Associated Types§

source

type Output

Type of the contained value.

Required Methods§

source

fn unwrap(self) -> Self::Output

Get the contained value.

Because this function may panic, its use is generally discouraged. Instead, use unwrap_or_default() or try_unwrap().

§Panic

Panic if self does not contain a value.

§Example
use tuplez::*;

let tup = tuple!(Some(1), Ok::<f32, ()>(3.14), Some("hello"));
assert_eq!(tup.unwrap(), tuple!(1, 3.14, "hello"));
source

fn has_value(&self) -> bool

Check if self contains a value.

Soundess requirement: When has_value() returns true, unwrap() cannot panic.

Implementations on Foreign Types§

source§

impl<T> Unwrap for Option<T>

§

type Output = T

source§

fn unwrap(self) -> Self::Output

source§

fn has_value(&self) -> bool

source§

impl<T, E: Debug> Unwrap for Result<T, E>

§

type Output = T

source§

fn unwrap(self) -> Self::Output

source§

fn has_value(&self) -> bool

Implementors§

source§

impl Unwrap for Unit

§

type Output = Unit

source§

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

§

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