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
use crate::bit::Bit;
use core::marker::PhantomData;

/// Type-level linked list, enum-like of [`Nil`] and [`Cons`]
pub trait List {
    #[cfg(not(feature = "no_std"))]
    /// Real value of type.
    fn val() -> Vec<bool>;
}

/// End of [`List`].
#[derive(Debug)]
pub struct Nil;

/// Node of list, consists of value ([`Bit`]) and tail -- [`List`].
#[derive(Debug)]
pub struct Cons<Value, Tail>(PhantomData<(Value, Tail)>)
where
    Value: Bit,
    Tail: List;

impl List for Nil {
    #[cfg(not(feature = "no_std"))]
    fn val() -> Vec<bool> {
        Vec::new()
    }
}

impl<Value, Tail> List for Cons<Value, Tail>
where
    Value: Bit,
    Tail: List,
{
    #[cfg(not(feature = "no_std"))]
    fn val() -> Vec<bool> {
        let mut vec = Tail::val();
        vec.push(Value::val());

        vec
    }
}