You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

80 lines
1.5 KiB

//! Tuple traits
use super::*;
pub trait TryUntupleTwoExt<T,U>: Sized
{
type Wrapper<S>;
fn both(self) -> Self::Wrapper<(T, U)>;
}
impl<T, U> TryUntupleTwoExt<T, U> for (T, Option<U>)
{
type Wrapper<S> = Option<S>;
#[inline]
fn both(self) -> Self::Wrapper<(T, U)> {
match self {
(first, Some(second)) => Some((first, second)),
_ => None,
}
}
}
impl<T, U> TryUntupleTwoExt<T, U> for (Option<T>, U)
{
type Wrapper<S> = Option<S>;
#[inline]
fn both(self) -> Self::Wrapper<(T, U)> {
match self {
(Some(first), second) => Some((first, second)),
_ => None,
}
}
}
impl<T, U> TryUntupleTwoExt<T, U> for (Option<T>, Option<U>)
{
type Wrapper<S> = Option<S>;
#[inline]
fn both(self) -> Self::Wrapper<(T, U)> {
match self {
(Some(first), Some(second)) => Some((first, second)),
_ => None,
}
}
}
pub trait UntupleTwoExt<T,U,V>: Sized
{
type Unwrapped<A,B,C>;
fn untuple(self) -> Self::Unwrapped<T,U,V>;
}
impl<T, U, V> UntupleTwoExt<T,U,V> for (T, (U, V))
{
type Unwrapped<A,B,C> = (A,B,C);
#[inline]
fn untuple(self) -> Self::Unwrapped<T,U,V> {
(self.0, self.1.0, self.1.1)
}
}
impl<T, U> UntupleTwoExt<T,U,()> for (T, (U,))
{
type Unwrapped<A,B,C> = (A,B);
#[inline]
fn untuple(self) -> Self::Unwrapped<T,U,()> {
(self.0, self.1.0)
}
}
impl<T> UntupleTwoExt<T,(),()> for (T,)
{
type Unwrapped<A,B,C> = A;
#[inline]
fn untuple(self) -> Self::Unwrapped<T,(),()> {
self.0
}
}