pub trait Tuple: Sealed {
type Head;
type Tail;
type Append<T>: Tuple;
type Prepend<T>: Tuple;
type TruncateHead: Tuple;
type TruncateTail: Tuple;
const ARITY: usize;
// Required methods
fn head(&self) -> &Self::Head;
fn head_mut(&mut self) -> &mut Self::Head;
fn tail(&self) -> &Self::Tail;
fn tail_mut(&mut self) -> &mut Self::Tail;
fn append<T>(self, value: T) -> Self::Append<T>;
fn prepend<T>(self, value: T) -> Self::Prepend<T>;
fn truncate_head(self) -> (Self::Head, Self::TruncateHead);
fn truncate_tail(self) -> (Self::TruncateTail, Self::Tail);
// Provided methods
fn replace_head(&mut self, head: Self::Head) -> Self::Head { ... }
fn take_head(&mut self) -> Self::Head
where Self::Head: Default { ... }
fn replace_tail(&mut self, tail: Self::Tail) -> Self::Tail { ... }
fn take_tail(&mut self) -> Self::Tail
where Self::Tail: Default { ... }
}
Expand description
A trait representing tuples. It is only implemented for tuples of arity 0 to 50.
This trait is sealed and as such not meant to be implemented.
The first element of this tuple.
The last element of this tuple.
This tuple with an extra element T appended to it.
This tuple with an extra element T prepended to it.
This tuple with its head truncated.
This tuple with its tail truncated.
The arity or length of this tuple type.
Returns a reference to the head of this tuple.
let tuple = (1, 2, 3);
assert_eq!(&1, tuple.head());
Calling this function on an empty tuple will cause a panic.
Returns a mutable reference to the head of this tuple.
let mut tuple = (1, 2, 3);
assert_eq!(&mut 1, tuple.head_mut());
Calling this function on an empty tuple will cause a panic.
Returns a reference to the tail of this tuple.
let tuple = (1, 2, 3);
assert_eq!(&3, tuple.tail());
Calling this function on an empty tuple will cause a panic.
Returns a mutable reference to the tail of this tuple.
let mut tuple = (1, 2, 3);
assert_eq!(&mut 3, tuple.tail_mut());
Calling this function on an empty tuple will cause a panic.
Consumes this tuple and appends a value to it, returning a new tuple.
let tuple = (1, 2);
let tuple = tuple.append(3);
assert_eq!(tuple, (1, 2, 3));
Calling this function on a tuple of arity 50 or greater will cause a panic.
Consumes this tuple and prepends a value to it, returning a new tuple.
let tuple = (2, 3);
let tuple = tuple.prepend(1);
assert_eq!(tuple, (1, 2, 3));
Calling this function on a tuple of arity 50 or greater will cause a panic.
Consumes this tuple and truncates its head from the remaining elements.
let tuple = (1, 2, 3);
let tuple = tuple.truncate_head();
assert_eq!(tuple, (1, (2, 3)));
Calling this function on an empty tuple will cause a panic.
Consumes this tuple and truncates its tail from the remaining elements.
let tuple = (1, 2, 3);
let tuple = tuple.truncate_tail();
assert_eq!(tuple, ((1, 2), 3));
Calling this function on an empty tuple will cause a panic.
Replaces the head of this tuple with a new value, returning the old one.
let mut tuple = (1, 2, 3);
let head = tuple.replace_head(-1);
assert_eq!(-1, tuple.0);
assert_eq!(1, head);
Calling this function on an empty tuple will cause a panic.
Takes the head of this tuple and replaces it with its default value, returning the current value.
let mut tuple = (1, 2, 3);
let head = tuple.take_head();
assert_eq!(0, tuple.0);
assert_eq!(1, head);
Calling this function on an empty tuple will cause a panic.
Replaces the tail of this tuple with a new value, returning the old one.
let mut tuple = (1, 2, 3);
let tail = tuple.replace_tail(4);
assert_eq!(4, tuple.2);
assert_eq!(3, tail);
Calling this function on an empty tuple will cause a panic.
Takes the tail of this tuple and replaces it with its default value, returning the current value.
let mut tuple = (1, 2, 3);
let tail = tuple.take_tail();
assert_eq!(0, tuple.2);
assert_eq!(3, tail);
Calling this function on an empty tuple will cause a panic.