@@ -29,6 +29,9 @@ pub use typenum::consts;
29
29
use core:: {
30
30
array:: { IntoIter , TryFromSliceError } ,
31
31
borrow:: { Borrow , BorrowMut } ,
32
+ cmp:: Ordering ,
33
+ fmt:: { self , Debug } ,
34
+ hash:: { Hash , Hasher } ,
32
35
ops:: { Deref , DerefMut , Index , IndexMut , Range } ,
33
36
slice:: { Iter , IterMut } ,
34
37
} ;
@@ -38,7 +41,6 @@ use typenum::Unsigned;
38
41
///
39
42
/// Provides the flexibility of typenum-based expressions while also
40
43
/// allowing interoperability and a transition path to const generics.
41
- #[ derive( Debug , Eq , Hash , PartialEq , PartialOrd , Ord ) ]
42
44
#[ repr( transparent) ]
43
45
pub struct Array < T , U : ArraySize > ( pub U :: ArrayType < T > ) ;
44
46
@@ -188,6 +190,17 @@ where
188
190
{
189
191
}
190
192
193
+ impl < T , U > Debug for Array < T , U >
194
+ where
195
+ T : Debug ,
196
+ U : ArraySize ,
197
+ U :: ArrayType < T > : Debug ,
198
+ {
199
+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
200
+ f. debug_tuple ( "Array" ) . field ( & self . 0 ) . finish ( )
201
+ }
202
+ }
203
+
191
204
impl < T , U > Default for Array < T , U >
192
205
where
193
206
T : Default ,
@@ -220,6 +233,13 @@ where
220
233
}
221
234
}
222
235
236
+ impl < T , U > Eq for Array < T , U >
237
+ where
238
+ T : Eq ,
239
+ U : ArraySize ,
240
+ {
241
+ }
242
+
223
243
impl < T , U , const N : usize > From < [ T ; N ] > for Array < T , U >
224
244
where
225
245
Self : ArrayOps < T , N > ,
@@ -253,6 +273,17 @@ where
253
273
}
254
274
}
255
275
276
+ impl < T , U > Hash for Array < T , U >
277
+ where
278
+ T : Hash ,
279
+ U : ArraySize ,
280
+ {
281
+ #[ inline]
282
+ fn hash < H : Hasher > ( & self , state : & mut H ) {
283
+ self . 0 . as_ref ( ) . hash ( state) ;
284
+ }
285
+ }
286
+
256
287
impl < T , I , U > Index < I > for Array < T , U >
257
288
where
258
289
[ T ] : Index < I > ,
@@ -277,6 +308,36 @@ where
277
308
}
278
309
}
279
310
311
+ impl < T , U > PartialEq for Array < T , U >
312
+ where
313
+ T : PartialEq ,
314
+ U : ArraySize ,
315
+ {
316
+ fn eq ( & self , other : & Self ) -> bool {
317
+ self . 0 . as_ref ( ) . eq ( other. 0 . as_ref ( ) )
318
+ }
319
+ }
320
+
321
+ impl < T , U > PartialOrd for Array < T , U >
322
+ where
323
+ T : PartialOrd ,
324
+ U : ArraySize ,
325
+ {
326
+ fn partial_cmp ( & self , other : & Self ) -> Option < Ordering > {
327
+ self . 0 . as_ref ( ) . partial_cmp ( other. 0 . as_ref ( ) )
328
+ }
329
+ }
330
+
331
+ impl < T , U > Ord for Array < T , U >
332
+ where
333
+ T : Ord ,
334
+ U : ArraySize ,
335
+ {
336
+ fn cmp ( & self , other : & Self ) -> Ordering {
337
+ self . 0 . as_ref ( ) . cmp ( other. 0 . as_ref ( ) )
338
+ }
339
+ }
340
+
280
341
impl < ' a , T , U > TryFrom < & ' a [ T ] > for Array < T , U >
281
342
where
282
343
T : Copy ,
0 commit comments