1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
use crate::{Cons, HList, Nil};
/// Append new element to the heterogenous list.
pub trait Append: HList {
/// Type of heterogenous list with new element.
type Output<T>: HList;
/// Appends new element to the heterogenous list.
///
/// New element will be placed at the end of the heterogenous list,
/// resulting in new heterogenous list.
///
/// # Examples
///
/// ```
/// use hlist2::{hlist, ops::Append};
///
/// let list = hlist![1, 2.0, true];
/// assert_eq!(list.append("hello world"), hlist![1, 2.0, true, "hello world"]);
/// ```
#[doc(alias("push", "push_back"))]
fn append<T>(self, value: T) -> Self::Output<T>;
}
impl Append for Nil {
type Output<T> = Cons<T, Nil>;
fn append<T>(self, value: T) -> Self::Output<T> {
Cons(value, self)
}
}
impl<Head, Tail> Append for Cons<Head, Tail>
where
Tail: Append,
{
type Output<T> = Cons<Head, Tail::Output<T>>;
fn append<T>(self, value: T) -> Self::Output<T> {
let Cons(head, tail) = self;
let tail = tail.append(value);
Cons(head, tail)
}
}