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
use crate::{Cons, HList};
/// Remove the first element from the heterogenous list.
pub trait PopFront: HList {
/// The first element of the heterogenous list.
type First;
/// Remaining part of the heterogenous list without the first element.
type Remainder: HList;
/// Removes the first element from the heterogenous list.
///
/// New element will be removed from the beginning of the heterogenous list,
/// resulting in pair of new heterogenous list and removed element.
///
/// # Examples
///
/// ```
/// use hlist2::{hlist, ops::PopFront};
///
/// let list = hlist![1, 2.0, true];
/// let (elem, list) = list.pop_front();
/// assert_eq!(elem, 1);
/// assert_eq!(list, hlist![2.0, true]);
/// ```
fn pop_front(self) -> (Self::First, Self::Remainder);
}
impl<Head, Tail> PopFront for Cons<Head, Tail>
where
Tail: HList,
{
type First = Head;
type Remainder = Tail;
fn pop_front(self) -> (Self::First, Self::Remainder) {
let Cons(head, tail) = self;
(head, tail)
}
}