@@ -429,6 +429,58 @@ macro_rules! impl_option_non_zero {
429
429
#[ cfg( target_has_atomic = "ptr" ) ] impl_option_non_zero ! ( NonZeroUsize = usize ) ;
430
430
#[ cfg( target_has_atomic = "ptr" ) ] impl_option_non_zero ! ( NonZeroIsize = isize ) ;
431
431
432
+ macro_rules! impl_int8_arrays {
433
+ ( $elem: ident, $len: literal, $repr: ident) => {
434
+ impl Atom for [ $elem; $len] {
435
+ type Repr = $repr;
436
+ fn pack( self ) -> Self :: Repr {
437
+ $repr:: from_ne_bytes( self . map( |e| e as _) )
438
+ }
439
+ fn unpack( src: Self :: Repr ) -> Self {
440
+ src. to_ne_bytes( ) . map( |e| e as _)
441
+ }
442
+ }
443
+ impl AtomLogic for [ $elem; $len] { }
444
+ } ;
445
+ }
446
+
447
+ #[ cfg( target_has_atomic = "16" ) ] impl_int8_arrays ! ( u8 , 2 , u16 ) ;
448
+ #[ cfg( target_has_atomic = "32" ) ] impl_int8_arrays ! ( u8 , 4 , u32 ) ;
449
+ #[ cfg( target_has_atomic = "64" ) ] impl_int8_arrays ! ( u8 , 8 , u64 ) ;
450
+ #[ cfg( target_has_atomic = "16" ) ] impl_int8_arrays ! ( i8 , 2 , u16 ) ;
451
+ #[ cfg( target_has_atomic = "32" ) ] impl_int8_arrays ! ( i8 , 4 , u32 ) ;
452
+ #[ cfg( target_has_atomic = "64" ) ] impl_int8_arrays ! ( i8 , 8 , u64 ) ;
453
+
454
+ macro_rules! impl_int_arrays {
455
+ ( $unsigned_elem: ident, $signed_elem: ident, $len: literal, $repr: ident, $nested: tt, $flat: tt) => {
456
+ impl_small_primitive_array!( $unsigned_elem, $len, $repr, $nested, $flat) ;
457
+ impl_small_primitive_array!( $signed_elem, $len, $repr, $nested, $flat) ;
458
+ } ;
459
+ }
460
+
461
+ macro_rules! impl_small_primitive_array {
462
+ ( $elem: ident, $len: literal, $repr: ident, $nested: tt, $flat: tt) => {
463
+ impl Atom for [ $elem; $len] {
464
+ type Repr = $repr;
465
+ fn pack( self ) -> Self :: Repr {
466
+ let $nested = self . map( |x| x. to_ne_bytes( ) ) ;
467
+ Self :: Repr :: from_ne_bytes( $flat)
468
+ }
469
+ fn unpack( src: Self :: Repr ) -> Self {
470
+ let $flat = src. to_ne_bytes( ) ;
471
+ $nested. map( $elem:: from_ne_bytes)
472
+ }
473
+ }
474
+ impl AtomLogic for [ $elem; $len] { }
475
+ } ;
476
+ }
477
+ #[ cfg( target_has_atomic = "32" ) ] impl_int_arrays ! ( u16 , i16 , 2 , u32 ,
478
+ [ [ b0, b1] , [ b2, b3] ] , [ b0, b1, b2, b3] ) ;
479
+ #[ cfg( target_has_atomic = "64" ) ] impl_int_arrays ! ( u16 , i16 , 4 , u64 ,
480
+ [ [ b0, b1] , [ b2, b3] , [ b4, b5] , [ b6, b7] ] , [ b0, b1, b2, b3, b4, b5, b6, b7] ) ;
481
+ #[ cfg( target_has_atomic = "64" ) ] impl_int_arrays ! ( u32 , i32 , 2 , u64 ,
482
+ [ [ b0, b1, b2, b3] , [ b4, b5, b6, b7] ] , [ b0, b1, b2, b3, b4, b5, b6, b7] ) ;
483
+
432
484
/// This is just a dummy module to have doc tests.
433
485
///
434
486
/// ```
@@ -468,6 +520,19 @@ macro_rules! impl_option_non_zero {
468
520
/// assert_impl_atom::<f32>();
469
521
/// assert_impl_atom::<f64>();
470
522
///
523
+ /// assert_impl_atom::<[u8; 2]>();
524
+ /// assert_impl_atom::<[u8; 4]>();
525
+ /// assert_impl_atom::<[u8; 8]>();
526
+ /// assert_impl_atom::<[i8; 2]>();
527
+ /// assert_impl_atom::<[i8; 4]>();
528
+ /// assert_impl_atom::<[i8; 8]>();
529
+ /// assert_impl_atom::<[u16; 2]>();
530
+ /// assert_impl_atom::<[u16; 4]>();
531
+ /// assert_impl_atom::<[i16; 2]>();
532
+ /// assert_impl_atom::<[i16; 4]>();
533
+ /// assert_impl_atom::<[u32; 2]>();
534
+ /// assert_impl_atom::<[i32; 2]>();
535
+ ///
471
536
/// assert_impl_atom::<core::num::NonZeroU8>();
472
537
/// assert_impl_atom::<core::num::NonZeroI8>();
473
538
/// assert_impl_atom::<core::num::NonZeroU16>();
0 commit comments