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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
//! Helper traits to work with type-level [cons-lists](https://en.wikipedia.org/wiki/Cons#Lists).
//!
//! These are useful when working with macros and traits that need to support arbitrary length type
//! lists, without having to macro generate hundreds of trait implementations for different length
//! tuples.
//!
//! Rather than using raw tuples `type Nil = (); type Cons<T, U> = (T, U);` this includes new
//! nominal types so that we can have safe pin-projection.
/// The terminal element of a cons-list.
;
/// Prepends an element to the cons-list, somewhat equivalent to the array `[T, ...U]`.
;
/// Internal helper that asserts post-normalization types are the same, see usage in below doc-tests.
/// Converts a tuple-based cons-list into one using our nominal types.
///
/// ```rust
/// use veecle_os_runtime::__assert_same_type;
/// use veecle_os_runtime::__exports::{Cons, Nil, TupleConsToCons};
///
/// __assert_same_type! {
/// for<>
/// <() as TupleConsToCons>::Cons,
/// Nil,
/// }
///
/// __assert_same_type! {
/// for<A, B, C>
/// <(A, (B, (C, ()))) as TupleConsToCons>::Cons,
/// Cons<A, Cons<B, Cons<C, Nil>>>,
/// }
/// ```
/// Given a list of types or values, generate a cons-list for those types or values.
///
/// ```rust
/// use veecle_os_runtime::{__assert_same_type, __make_cons};
/// use veecle_os_runtime::__exports::{Cons, Nil};
///
/// __assert_same_type! {
/// for<>
/// __make_cons!(@type),
/// Nil,
/// }
///
/// __assert_same_type! {
/// for<A, B, C>
/// __make_cons!(@type A, B, C),
/// Cons<A, Cons<B, Cons<C, Nil>>>,
/// }
///
/// assert_eq! {
/// __make_cons!(@value),
/// Nil,
/// }
///
/// assert_eq! {
/// __make_cons!(@value 1u32, "hello ferris", 3.141594f64),
/// Cons(1, Cons("hello ferris", Cons(3.141594, Nil))),
/// }
/// ```
/// Given a cons-list value, and a depth denoted by a series of any kind of token-tree, read the value at that depth
/// from the list.
///
/// ```rust
/// use veecle_os_runtime::{__make_cons, __read_cons};
///
/// let cons = __make_cons!(@value 1u32, "hello ferris", 3.141594f64);
///
/// assert_eq! {
/// __read_cons! {
/// from: cons,
/// depth: [],
/// },
/// 1u32,
/// }
///
/// assert_eq! {
/// __read_cons! {
/// from: cons,
/// depth: [()],
/// },
/// "hello ferris",
/// }
///
/// assert_eq! {
/// __read_cons! {
/// from: cons,
/// depth: [() ()],
/// },
/// 3.141594f64,
/// }
/// ```