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
use super::{Cons, HList, Nil};
pub trait PushFront<H>: HList + Sized {
fn push_front(self, head: H) -> Cons<H, Self> {
Cons(head, self)
}
}
pub trait PushBack<I>: HList {
type Out;
fn push_back(self, item: I) -> Self::Out;
}
impl<H, L> PushFront<H> for L where L: HList {}
impl<I> PushBack<I> for Nil {
type Out = Cons<I, Self>;
fn push_back(self, item: I) -> Self::Out {
Cons(item, self)
}
}
impl<I, H, T> PushBack<I> for Cons<H, T>
where
T: PushBack<I>,
{
type Out = Cons<H, <T as PushBack<I>>::Out>;
fn push_back(self, item: I) -> Self::Out {
Cons(self.0, self.1.push_back(item))
}
}