Trait wlan_fidl_ext::try_unpack::TryUnpack

source ·
pub trait TryUnpack {
    type Unpacked;
    type Error;

    // Required method
    fn try_unpack(self) -> Result<Self::Unpacked, Self::Error>;
}
Expand description

A trait for attempting to unpack the values of one type into another.

§Examples

Basic usage:

impl<T, U> TryUnpack for (Option<T>, Option<U>) {
    type Unpacked = (T, U);
    type Error = ();

    fn try_unpack(self) -> Result<Self::Unpacked, Self::Error> {
        match self {
            (Some(t), Some(u)) => Ok((t, u)),
            _ => Err(()),
        }
    }
}

assert_eq!(Ok((1i8, 2u8)), (Some(1i8), Some(2u8)).try_unpack());
assert_eq!(Err(()), (Some(1i8), None).try_unpack());

Required Associated Types§

Required Methods§

source

fn try_unpack(self) -> Result<Self::Unpacked, Self::Error>

Tries to unpack value(s) from self and returns a Self::Error if the operation fails.

Implementations on Foreign Types§

source§

impl<T1, A1: Display, T2, A2: Display> TryUnpack for (NamedField<Option<T1>, A1>, NamedField<Option<T2>, A2>)

source§

fn try_unpack(self) -> Result<Self::Unpacked, Self::Error>

Tries to unpack values from a tuple of n fields each with type NamedField<Option<Tᵢ>, Aᵢ: Display>.

If every Option<Tᵢ> contains a value, then the returned value has the type (T₁, T₂, …, Tₙ), i.e., every value is unwrapped, and every name is discarded. Otherwise, the returned value is a Self::Error containing name of each field missing a value.

§

type Unpacked = (T1, T2)

§

type Error = Error

source§

impl<T1, A1: Display, T2, A2: Display, T3, A3: Display> TryUnpack for (NamedField<Option<T1>, A1>, NamedField<Option<T2>, A2>, NamedField<Option<T3>, A3>)

source§

fn try_unpack(self) -> Result<Self::Unpacked, Self::Error>

Tries to unpack values from a tuple of n fields each with type NamedField<Option<Tᵢ>, Aᵢ: Display>.

If every Option<Tᵢ> contains a value, then the returned value has the type (T₁, T₂, …, Tₙ), i.e., every value is unwrapped, and every name is discarded. Otherwise, the returned value is a Self::Error containing name of each field missing a value.

§

type Unpacked = (T1, T2, T3)

§

type Error = Error

source§

impl<T1, A1: Display, T2, A2: Display, T3, A3: Display, T4, A4: Display> TryUnpack for (NamedField<Option<T1>, A1>, NamedField<Option<T2>, A2>, NamedField<Option<T3>, A3>, NamedField<Option<T4>, A4>)

source§

fn try_unpack(self) -> Result<Self::Unpacked, Self::Error>

Tries to unpack values from a tuple of n fields each with type NamedField<Option<Tᵢ>, Aᵢ: Display>.

If every Option<Tᵢ> contains a value, then the returned value has the type (T₁, T₂, …, Tₙ), i.e., every value is unwrapped, and every name is discarded. Otherwise, the returned value is a Self::Error containing name of each field missing a value.

§

type Unpacked = (T1, T2, T3, T4)

§

type Error = Error

source§

impl<T1, A1: Display, T2, A2: Display, T3, A3: Display, T4, A4: Display, T5, A5: Display> TryUnpack for (NamedField<Option<T1>, A1>, NamedField<Option<T2>, A2>, NamedField<Option<T3>, A3>, NamedField<Option<T4>, A4>, NamedField<Option<T5>, A5>)

source§

fn try_unpack(self) -> Result<Self::Unpacked, Self::Error>

Tries to unpack values from a tuple of n fields each with type NamedField<Option<Tᵢ>, Aᵢ: Display>.

If every Option<Tᵢ> contains a value, then the returned value has the type (T₁, T₂, …, Tₙ), i.e., every value is unwrapped, and every name is discarded. Otherwise, the returned value is a Self::Error containing name of each field missing a value.

§

type Unpacked = (T1, T2, T3, T4, T5)

§

type Error = Error

Implementors§

source§

impl<T1, A1: Display> TryUnpack for NamedField<Option<T1>, A1>

§

type Unpacked = T1

§

type Error = Error