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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
use crate::{Cons, HList, Nil};
/// Extend heterogenous list with another heterogenous list.
pub trait Extend: HList {
/// Type of heterogenous list extended with elements of another heterogenous list.
type Output<T>: HList
where
T: HList;
/// Extends heterogenous list with another heterogenous list.
///
/// Elements of another heterogenous list will be placed at the end
/// of the current heterogenous list in the order of which they was in another list.
///
/// # Examples
///
/// ```
/// use hlist2::{hlist, ops::Extend};
///
/// let first = hlist![1, 2.0];
/// let second = hlist![true, "hello world"];
/// assert_eq!(first.extend(second), hlist![1, 2.0, true, "hello world"]);
/// assert_eq!(second.extend(first), hlist![true, "hello world", 1, 2.0]);
/// ```
#[doc(alias("append_many"))]
fn extend<T>(self, list: T) -> Self::Output<T>
where
T: HList;
}
impl Extend for Nil {
type Output<T> = T
where
T: HList;
fn extend<T>(self, list: T) -> Self::Output<T>
where
T: HList,
{
list
}
}
impl<Head, Tail> Extend for Cons<Head, Tail>
where
Tail: Extend,
{
type Output<T> = Cons<Head, Tail::Output<T>>
where
T: HList;
fn extend<T>(self, list: T) -> Self::Output<T>
where
T: HList,
{
let Cons(head, tail) = self;
let tail = tail.extend(list);
Cons(head, tail)
}
}