structural/path/
array_paths.rs

1//! Traits for paths when used for arrays,and aliases for indices up to 31.
2//!
3
4use super::IsSingleFieldPath;
5
6use crate::field::FieldBit;
7
8mod sealed {
9    pub trait Sealed {}
10}
11use self::sealed::Sealed;
12
13/// A field path that is usable for indexing (some) arrays.
14pub trait ArrayPath: IsSingleFieldPath + Sealed {
15    /// The index that this type represents.
16    const INDEX: usize;
17
18    /// The `FieldBit` for the field whose index is`Self::Index`.
19    const DROP_BIT: FieldBit = FieldBit::new(Self::INDEX as u8);
20}
21
22/// Used to check whether this field path is valid for `Array`.
23///
24/// # Safety
25///
26/// Implementors must ensure that `<Self as ArrayPath>::INDEX` is in bounds for
27/// the `Array` type parameter.
28pub unsafe trait IsPathForArray<Array>: ArrayPath {}
29
30macro_rules! impl_is_path_for_array {
31    (
32        $( $path:ident[$index:expr; $($i:expr,)* ] )*
33    ) => (
34        crate::tstr_aliases!{
35            $( $path = $index ,)*
36        }
37        $(
38            impl Sealed for $path{}
39
40            impl ArrayPath for $path{
41                const INDEX:usize=$index;
42            }
43            $(
44                unsafe impl<T> IsPathForArray<[T;$i]> for $path{}
45            )*
46        )*
47    );
48}
49
50/*
51fn main(){
52    for path in 0..=31 {
53        print!("I{}[",path);
54        for array in path+1..=32 {
55            print!("{},",array);
56        }
57        println!("]");
58    }
59}
60*/
61
62impl_is_path_for_array! {
63    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,]
64    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,]
65    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,]
66    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,]
67    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,]
68    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,]
69    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,]
70    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,]
71    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,]
72    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,]
73    I10[10;11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,]
74    I11[11;12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,]
75    I12[12;13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,]
76    I13[13;14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,]
77    I14[14;15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,]
78    I15[15;16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,]
79    I16[16;17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,]
80    I17[17;18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,]
81    I18[18;19,20,21,22,23,24,25,26,27,28,29,30,31,32,]
82    I19[19;20,21,22,23,24,25,26,27,28,29,30,31,32,]
83    I20[20;21,22,23,24,25,26,27,28,29,30,31,32,]
84    I21[21;22,23,24,25,26,27,28,29,30,31,32,]
85    I22[22;23,24,25,26,27,28,29,30,31,32,]
86    I23[23;24,25,26,27,28,29,30,31,32,]
87    I24[24;25,26,27,28,29,30,31,32,]
88    I25[25;26,27,28,29,30,31,32,]
89    I26[26;27,28,29,30,31,32,]
90    I27[27;28,29,30,31,32,]
91    I28[28;29,30,31,32,]
92    I29[29;30,31,32,]
93    I30[30;31,32,]
94    I31[31;32,]
95}