[][src]Trait tuple_list::NonEmptyTuple

pub trait NonEmptyTuple: Tuple {
    type Head;
    type Tail: Tuple;
    fn uncons(self) -> (Self::Head, Self::Tail);
fn head(self) -> Self::Head;
fn tail(self) -> Self::Tail; }

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.

Associated Types

type Head

First element of Self tuple.

type Tail: Tuple

Tuple of remaining elements of Self tuple.

Loading content...

Required methods

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, ());
Run

fn head(self) -> Self::Head

Returns first element of a tuple.

Same as NonEmptyTuple::uncons().0.

fn tail(self) -> Self::Tail

Returns all but the first element of a tuple.

Same as NonEmptyTuple::uncons().1.

Loading content...

Implementations on Foreign Types

impl<T1> NonEmptyTuple for (T1,)[src]

type Head = T1

type Tail = ()

impl<T1, T2> NonEmptyTuple for (T1, T2)[src]

type Head = T1

type Tail = (T2,)

impl<T1, T2, T3> NonEmptyTuple for (T1, T2, T3)[src]

type Head = T1

type Tail = (T2, T3)

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

type Head = T1

type Tail = (T2, T3, T4)

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

type Head = T1

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

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

type Head = T1

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

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

type Head = T1

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

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

type Head = T1

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

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

type Head = T1

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

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

type Head = T1

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

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)[src]

type Head = T1

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

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)[src]

type Head = T1

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

Loading content...

Implementors

Loading content...