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
#![cfg_attr(feature = "nightly", feature(allow_internal_unstable, macro_reexport))]
#[cfg(feature = "nightly")]
#[macro_reexport(lazy_static, __lazy_static_create)]
#[macro_use]
extern crate lazy_static;
#[cfg(feature = "nightly")]
pub use lazy_static::lazy;
#[macro_export]
macro_rules! counted_array {
(@parse $size:expr, ($val:expr) -> [$($accs:expr),*] $thru:tt) => {
counted_array!(@output $size + 1usize, [$($accs,)* $val] $thru);
};
(@parse $size:expr, ($val:expr, $($vals:expr),*) -> [$($accs:expr),*] $thru:tt) => {
counted_array!(@parse $size + 1usize, ($($vals),*) -> [$($accs,)* $val] $thru);
};
(@output $size:expr, $acc:tt (() let $n:ident $t:ty)) => {
let $n: [$t; $size] = $acc;
};
(@output $size:expr, $acc:tt (($($p:tt)*) lazy_static $n:ident $t:ty)) => {
lazy_static!{ $($p)* static ref $n: [$t; $size] = $acc; }
};
(@output $size:expr, $acc:tt (($($p:tt)*) $s:ident $n:ident $t:ty)) => {
$($p)* $s $n: [$t; $size] = $acc;
};
(pub $storage:ident $n:ident: [$t:ty; _] = [$($vals:expr),* $(,)*]) => {
counted_array!(@parse 0usize, ($($vals),*) -> [] ((pub) $storage $n $t));
};
($storage:ident $n:ident: [$t:ty; _] = [$($vals:expr),* $(,)*]) => {
counted_array!(@parse 0usize, ($($vals),*) -> [] (() $storage $n $t));
};
}