@@ -14,49 +14,78 @@ pub unsafe trait Array: 'static {
1414 fn capacity ( ) -> usize ;
1515}
1616
17- macro_rules! impl_array {
18- ( ) => ( ) ;
17+ #[ cfg( not( feature = "const_generics" ) ) ]
18+ mod impl_array {
19+ use super :: * ;
20+
21+ macro_rules! impl_array {
22+ ( ) => ( ) ;
23+
24+ ( $n: expr, $( $ns: expr, ) * ) => (
25+ unsafe impl <T : ' static > Array for [ T ; $n] {
26+ type Item = T ;
27+
28+ #[ inline( always) ]
29+ fn as_ptr( & self ) -> * const T {
30+ self as * const _ as * const _
31+ }
32+
33+ #[ inline( always) ]
34+ fn as_mut_ptr( & mut self ) -> * mut T {
35+ self as * mut _ as * mut _
36+ }
37+
38+ #[ inline( always) ]
39+ fn capacity( ) -> usize {
40+ $n
41+ }
42+ }
1943
20- ( $n : expr , $ ( $ns: expr , ) * ) => (
21- unsafe impl < T : ' static > Array for [ T ; $n ] {
22- type Item = T ;
44+ impl_array! ( $ ( $ns, ) * ) ;
45+ ) ;
46+ }
2347
24- #[ inline( always) ]
25- fn as_ptr( & self ) -> * const T {
26- self as * const _ as * const _
27- }
48+ impl_array ! (
49+ 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 ,
50+ 25 , 26 , 27 , 28 , 29 , 30 , 31 ,
51+ ) ;
52+ impl_array ! (
53+ 32 , 33 , 34 , 35 , 36 , 37 , 38 , 39 , 40 , 41 , 42 , 43 , 44 , 45 , 46 , 47 , 48 , 49 , 50 , 51 , 52 , 53 , 54 ,
54+ 55 , 56 , 57 , 58 , 59 , 60 , 61 , 62 , 63 ,
55+ ) ;
56+ impl_array ! (
57+ 64 , 70 , 72 , 80 , 90 , 96 , 100 , 110 , 120 , 128 , 130 , 140 , 150 , 160 , 170 , 180 , 190 , 192 , 200 ,
58+ 210 , 220 , 224 , 230 , 240 , 250 ,
59+ ) ;
60+ impl_array ! (
61+ 256 , 300 , 365 , 366 , 384 , 400 , 500 , 512 , 600 , 700 , 768 , 800 , 900 , 1000 , 1024 , 2048 , 4096 ,
62+ 8192 , 16384 , 32768 ,
63+ ) ;
64+ }
2865
29- #[ inline( always) ]
30- fn as_mut_ptr( & mut self ) -> * mut T {
31- self as * mut _ as * mut _
32- }
66+ #[ cfg( feature = "const_generics" ) ]
67+ mod impl_array {
68+ use super :: * ;
3369
34- #[ inline( always) ]
35- fn capacity( ) -> usize {
36- $n
37- }
70+ unsafe impl < T : ' static , const N : usize > Array for [ T ; N ] {
71+ type Item = T ;
72+
73+ #[ inline( always) ]
74+ fn as_ptr ( & self ) -> * const T {
75+ self as * const _
3876 }
3977
40- impl_array!( $( $ns, ) * ) ;
41- ) ;
42- }
78+ #[ inline( always) ]
79+ fn as_mut_ptr ( & mut self ) -> * mut T {
80+ self as * mut _ as * mut _
81+ }
4382
44- impl_array ! (
45- 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 ,
46- 26 , 27 , 28 , 29 , 30 , 31 ,
47- ) ;
48- impl_array ! (
49- 32 , 33 , 34 , 35 , 36 , 37 , 38 , 39 , 40 , 41 , 42 , 43 , 44 , 45 , 46 , 47 , 48 , 49 , 50 , 51 , 52 , 53 , 54 , 55 ,
50- 56 , 57 , 58 , 59 , 60 , 61 , 62 , 63 ,
51- ) ;
52- impl_array ! (
53- 64 , 70 , 72 , 80 , 90 , 96 , 100 , 110 , 120 , 128 , 130 , 140 , 150 , 160 , 170 , 180 , 190 , 192 , 200 , 210 ,
54- 220 , 224 , 230 , 240 , 250 ,
55- ) ;
56- impl_array ! (
57- 256 , 300 , 384 , 400 , 500 , 512 , 600 , 700 , 768 , 800 , 900 , 1000 , 1024 , 2048 , 4096 , 8192 , 16384 ,
58- 32768 ,
59- ) ;
83+ #[ inline( always) ]
84+ fn capacity ( ) -> usize {
85+ N
86+ }
87+ }
88+ }
6089
6190#[ repr( C ) ]
6291pub struct VarLenArray < T : Copy > {
0 commit comments