NonEmptyTuple

Trait NonEmptyTuple 

Source
pub trait NonEmptyTuple: Tuple {
    type Head;
    type Tail: Tuple;

    // Required methods
    fn uncons(self) -> (Self::Head, Self::Tail);
    fn head(self) -> Self::Head;
    fn tail(self) -> Self::Tail;
}
Expand description

Trait allowing to recursively deconstruct tuples.

Generic trait implemented for all non-empty tuples (up to 12 elements).

Most interesting part is that this trait allows you to recursively define some simple traits for regular tuples.

Unofrtunately, it’s not quite complete and is pretty unusable as of now.

In order ot be usable outside of this crate it needs support for trait specializations in Rust.

Required Associated Types§

Source

type Head

First element of Self tuple.

Source

type Tail: Tuple

Tuple of remaining elements of Self tuple.

Required Methods§

Source

fn uncons(self) -> (Self::Head, Self::Tail)

Splits Self tuple into head value and tail tuple.

Reverse of TupleCons::cons.

§Examples
use tuple_list::NonEmptyTuple;
 
let abcz = (4, false, "foo");
 
let (a, bcz) = NonEmptyTuple::uncons(abcz);
assert_eq!(a, 4);
assert_eq!(bcz, (false, "foo"));
 
let (b, cz) = NonEmptyTuple::uncons(bcz);
assert_eq!(b, false);
assert_eq!(cz, ("foo",));
 
let (c, z)  = NonEmptyTuple::uncons(cz);
assert_eq!(c, "foo");
assert_eq!(z, ());
Source

fn head(self) -> Self::Head

Returns first element of a tuple.

Same as NonEmptyTuple::uncons().0.

Source

fn tail(self) -> Self::Tail

Returns all but the first element of a tuple.

Same as NonEmptyTuple::uncons().1.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl<T1> NonEmptyTuple for (T1,)

Source§

type Head = T1

Source§

type Tail = ()

Source§

fn uncons(self) -> (Self::Head, Self::Tail)

Source§

fn head(self) -> Self::Head

Source§

fn tail(self) -> Self::Tail

Source§

impl<T1, T2> NonEmptyTuple for (T1, T2)

Source§

type Head = T1

Source§

type Tail = (T2,)

Source§

fn uncons(self) -> (Self::Head, Self::Tail)

Source§

fn head(self) -> Self::Head

Source§

fn tail(self) -> Self::Tail

Source§

impl<T1, T2, T3> NonEmptyTuple for (T1, T2, T3)

Source§

type Head = T1

Source§

type Tail = (T2, T3)

Source§

fn uncons(self) -> (Self::Head, Self::Tail)

Source§

fn head(self) -> Self::Head

Source§

fn tail(self) -> Self::Tail

Source§

impl<T1, T2, T3, T4> NonEmptyTuple for (T1, T2, T3, T4)

Source§

type Head = T1

Source§

type Tail = (T2, T3, T4)

Source§

fn uncons(self) -> (Self::Head, Self::Tail)

Source§

fn head(self) -> Self::Head

Source§

fn tail(self) -> Self::Tail

Source§

impl<T1, T2, T3, T4, T5> NonEmptyTuple for (T1, T2, T3, T4, T5)

Source§

type Head = T1

Source§

type Tail = (T2, T3, T4, T5)

Source§

fn uncons(self) -> (Self::Head, Self::Tail)

Source§

fn head(self) -> Self::Head

Source§

fn tail(self) -> Self::Tail

Source§

impl<T1, T2, T3, T4, T5, T6> NonEmptyTuple for (T1, T2, T3, T4, T5, T6)

Source§

type Head = T1

Source§

type Tail = (T2, T3, T4, T5, T6)

Source§

fn uncons(self) -> (Self::Head, Self::Tail)

Source§

fn head(self) -> Self::Head

Source§

fn tail(self) -> Self::Tail

Source§

impl<T1, T2, T3, T4, T5, T6, T7> NonEmptyTuple for (T1, T2, T3, T4, T5, T6, T7)

Source§

type Head = T1

Source§

type Tail = (T2, T3, T4, T5, T6, T7)

Source§

fn uncons(self) -> (Self::Head, Self::Tail)

Source§

fn head(self) -> Self::Head

Source§

fn tail(self) -> Self::Tail

Source§

impl<T1, T2, T3, T4, T5, T6, T7, T8> NonEmptyTuple for (T1, T2, T3, T4, T5, T6, T7, T8)

Source§

type Head = T1

Source§

type Tail = (T2, T3, T4, T5, T6, T7, T8)

Source§

fn uncons(self) -> (Self::Head, Self::Tail)

Source§

fn head(self) -> Self::Head

Source§

fn tail(self) -> Self::Tail

Source§

impl<T1, T2, T3, T4, T5, T6, T7, T8, T9> NonEmptyTuple for (T1, T2, T3, T4, T5, T6, T7, T8, T9)

Source§

type Head = T1

Source§

type Tail = (T2, T3, T4, T5, T6, T7, T8, T9)

Source§

fn uncons(self) -> (Self::Head, Self::Tail)

Source§

fn head(self) -> Self::Head

Source§

fn tail(self) -> Self::Tail

Source§

impl<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10> NonEmptyTuple for (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10)

Source§

type Head = T1

Source§

type Tail = (T2, T3, T4, T5, T6, T7, T8, T9, T10)

Source§

fn uncons(self) -> (Self::Head, Self::Tail)

Source§

fn head(self) -> Self::Head

Source§

fn tail(self) -> Self::Tail

Source§

impl<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11> NonEmptyTuple for (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11)

Source§

type Head = T1

Source§

type Tail = (T2, T3, T4, T5, T6, T7, T8, T9, T10, T11)

Source§

fn uncons(self) -> (Self::Head, Self::Tail)

Source§

fn head(self) -> Self::Head

Source§

fn tail(self) -> Self::Tail

Source§

impl<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12> NonEmptyTuple for (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12)

Source§

type Head = T1

Source§

type Tail = (T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12)

Source§

fn uncons(self) -> (Self::Head, Self::Tail)

Source§

fn head(self) -> Self::Head

Source§

fn tail(self) -> Self::Tail

Implementors§