@@ -14,76 +14,22 @@ pub unsafe trait Array: 'static {
14
14
fn capacity ( ) -> usize ;
15
15
}
16
16
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
- }
17
+ unsafe impl < T : ' static , const N : usize > Array for [ T ; N ] {
18
+ type Item = T ;
43
19
44
- impl_array!( $( $ns, ) * ) ;
45
- ) ;
20
+ #[ inline( always) ]
21
+ fn as_ptr ( & self ) -> * const T {
22
+ self as * const _
46
23
}
47
24
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
- }
65
-
66
- #[ cfg( feature = "const_generics" ) ]
67
- mod impl_array {
68
- use super :: * ;
69
-
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 _
76
- }
77
-
78
- #[ inline( always) ]
79
- fn as_mut_ptr ( & mut self ) -> * mut T {
80
- self as * mut _ as * mut _
81
- }
25
+ #[ inline( always) ]
26
+ fn as_mut_ptr ( & mut self ) -> * mut T {
27
+ self as * mut _ as * mut _
28
+ }
82
29
83
- #[ inline( always) ]
84
- fn capacity ( ) -> usize {
85
- N
86
- }
30
+ #[ inline( always) ]
31
+ fn capacity ( ) -> usize {
32
+ N
87
33
}
88
34
}
89
35
@@ -97,7 +43,7 @@ pub struct VarLenArray<T: Copy> {
97
43
impl < T : Copy > VarLenArray < T > {
98
44
pub unsafe fn from_parts ( p : * const T , len : usize ) -> VarLenArray < T > {
99
45
let ( len, ptr) = if !p. is_null ( ) && len != 0 {
100
- let dst = libc :: malloc ( len * mem:: size_of :: < T > ( ) ) ;
46
+ let dst = crate :: malloc ( len * mem:: size_of :: < T > ( ) ) ;
101
47
ptr:: copy_nonoverlapping ( p, dst as * mut _ , len) ;
102
48
( len, dst)
103
49
} else {
@@ -136,7 +82,7 @@ impl<T: Copy> Drop for VarLenArray<T> {
136
82
fn drop ( & mut self ) {
137
83
if !self . ptr . is_null ( ) {
138
84
unsafe {
139
- libc :: free ( self . ptr as * mut _ ) ;
85
+ crate :: free ( self . ptr as * mut _ ) ;
140
86
}
141
87
self . ptr = ptr:: null ( ) ;
142
88
if self . len != 0 {
@@ -173,10 +119,10 @@ impl<'a, T: Copy> From<&'a [T]> for VarLenArray<T> {
173
119
}
174
120
}
175
121
176
- impl < T : Copy > Into < Vec < T > > for VarLenArray < T > {
122
+ impl < T : Copy > From < VarLenArray < T > > for Vec < T > {
177
123
#[ inline]
178
- fn into ( self ) -> Vec < T > {
179
- self . iter ( ) . cloned ( ) . collect ( )
124
+ fn from ( v : VarLenArray < T > ) -> Self {
125
+ v . iter ( ) . cloned ( ) . collect ( )
180
126
}
181
127
}
182
128
0 commit comments