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§
Required Methods§
Sourcefn uncons(self) -> (Self::Head, Self::Tail)
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, ());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.