Trait tuple_list::NonEmptyTuple[][src]

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; }
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.

Associated Types

First element of Self tuple.

Tuple of remaining elements of Self tuple.

Required methods

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

Returns first element of a tuple.

Same as NonEmptyTuple::uncons().0.

Returns all but the first element of a tuple.

Same as NonEmptyTuple::uncons().1.

Implementations on Foreign Types

Implementors