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
//! Traits for paths when used for arrays,and aliases for indices up to 31.
//!

use super::IsSingleFieldPath;

use crate::field::FieldBit;

mod sealed {
    pub trait Sealed {}
}
use self::sealed::Sealed;

/// A field path that is usable for indexing (some) arrays.
pub trait ArrayPath: IsSingleFieldPath + Sealed {
    /// The index that this type represents.
    const INDEX: usize;

    /// The `FieldBit` for the field whose index is`Self::Index`.
    const DROP_BIT: FieldBit = FieldBit::new(Self::INDEX as u8);
}

/// Used to check whether this field path is valid for `Array`.
///
/// # Safety
///
/// Implementors must ensure that `<Self as ArrayPath>::INDEX` is in bounds for
/// the `Array` type parameter.
pub unsafe trait IsPathForArray<Array>: ArrayPath {}

macro_rules! impl_is_path_for_array {
    (
        $( $path:ident[$index:expr; $($i:expr,)* ] )*
    ) => (
        crate::tstr_aliases!{
            $( $path = $index ,)*
        }
        $(
            impl Sealed for $path{}

            impl ArrayPath for $path{
                const INDEX:usize=$index;
            }
            $(
                unsafe impl<T> IsPathForArray<[T;$i]> for $path{}
            )*
        )*
    );
}

/*
fn main(){
    for path in 0..=31 {
        print!("I{}[",path);
        for array in path+1..=32 {
            print!("{},",array);
        }
        println!("]");
    }
}
*/

impl_is_path_for_array! {
    I0[0;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,]
    I1[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,]
    I2[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,]
    I3[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,]
    I4[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,]
    I5[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,]
    I6[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,]
    I7[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,]
    I8[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,]
    I9[9;10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,]
    I10[10;11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,]
    I11[11;12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,]
    I12[12;13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,]
    I13[13;14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,]
    I14[14;15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,]
    I15[15;16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,]
    I16[16;17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,]
    I17[17;18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,]
    I18[18;19,20,21,22,23,24,25,26,27,28,29,30,31,32,]
    I19[19;20,21,22,23,24,25,26,27,28,29,30,31,32,]
    I20[20;21,22,23,24,25,26,27,28,29,30,31,32,]
    I21[21;22,23,24,25,26,27,28,29,30,31,32,]
    I22[22;23,24,25,26,27,28,29,30,31,32,]
    I23[23;24,25,26,27,28,29,30,31,32,]
    I24[24;25,26,27,28,29,30,31,32,]
    I25[25;26,27,28,29,30,31,32,]
    I26[26;27,28,29,30,31,32,]
    I27[27;28,29,30,31,32,]
    I28[28;29,30,31,32,]
    I29[29;30,31,32,]
    I30[30;31,32,]
    I31[31;32,]
}