@@ -45,7 +45,6 @@ pub mod intrinsics {
45
45
46
46
/// Swap bytes for `u8` slices on all targets.
47
47
pub mod u8 {
48
- use std:: num:: Int ;
49
48
use std:: ptr;
50
49
use std:: mem;
51
50
use std:: error;
@@ -56,7 +55,7 @@ pub mod u8 {
56
55
#[ inline]
57
56
pub unsafe fn align_of_ptr ( src : * const u8 ) -> usize {
58
57
let off: usize = mem:: transmute ( src) ;
59
- 2 . pow ( off. trailing_zeros ( ) as u32 )
58
+ 2usize . pow ( off. trailing_zeros ( ) as u32 )
60
59
}
61
60
62
61
/// TODO
@@ -69,9 +68,9 @@ pub mod u8 {
69
68
#[ inline]
70
69
pub fn reverse_slice ( dst : & mut [ u8 ] , src : & [ u8 ] ) {
71
70
unsafe {
72
- ptr:: copy_nonoverlapping ( dst . as_mut_ptr ( ) ,
73
- src . as_ptr ( ) ,
74
- src. len ( ) ) ;
71
+ ptr:: copy_nonoverlapping ( src . as_ptr ( ) ,
72
+ dst . as_mut_ptr ( ) ,
73
+ src. len ( ) ) ;
75
74
}
76
75
dst. reverse ( ) ;
77
76
}
@@ -124,7 +123,7 @@ pub mod u8 {
124
123
}
125
124
126
125
/// Errors that can occur when decoding a hex encoded string
127
- #[ derive( Copy ) ]
126
+ #[ derive( Copy , Clone ) ]
128
127
pub enum FromHexError {
129
128
/// The input contained a character not part of the hex format
130
129
InvalidHexCharacter ( char , usize ) ,
@@ -354,7 +353,6 @@ pub mod u56 {
354
353
/// Swap bytes for `u32` objects on all targets.
355
354
pub mod u32 {
356
355
use std:: cmp;
357
- use std:: num:: Int ;
358
356
pub const BYTES : usize = 4 ;
359
357
360
358
@@ -428,7 +426,6 @@ pub mod u32 {
428
426
/// Swap bytes for `u64` objects on all targets.
429
427
pub mod u64 {
430
428
use std:: cmp;
431
- use std:: num:: Int ;
432
429
pub const BYTES : usize = 7 ;
433
430
434
431
/// Swaps `len*8` bytes for `u64` objects inplace in `buf`.
@@ -505,7 +502,6 @@ pub mod u64 {
505
502
}
506
503
507
504
pub mod beusize {
508
- use std:: num:: Int ;
509
505
use std:: ptr;
510
506
use std:: mem;
511
507
@@ -517,7 +513,7 @@ pub mod beusize {
517
513
let ptr_out = dst. as_mut_ptr ( ) ;
518
514
unsafe {
519
515
ptr:: copy_nonoverlapping (
520
- ptr_out. offset ( ( 8 - nbytes) as isize ) , src . as_ptr ( ) , nbytes) ;
516
+ src . as_ptr ( ) , ptr_out. offset ( ( 8 - nbytes) as isize ) , nbytes) ;
521
517
( * ( ptr_out as * const u64 ) ) . to_be ( )
522
518
}
523
519
}
@@ -530,13 +526,12 @@ pub mod beusize {
530
526
// n.b. https://github.com/rust-lang/rust/issues/22776
531
527
let bytes: [ u8 ; 8 ] = mem:: transmute :: < _ , [ u8 ; 8 ] > ( src. to_be ( ) ) ;
532
528
ptr:: copy_nonoverlapping (
533
- dst . as_mut_ptr ( ) , ( & bytes[ 8 - nbytes..] ) . as_ptr ( ) , nbytes) ;
529
+ ( & bytes[ 8 - nbytes..] ) . as_ptr ( ) , dst . as_mut_ptr ( ) , nbytes) ;
534
530
}
535
531
}
536
532
}
537
533
538
534
pub mod leusize {
539
- use std:: num:: Int ;
540
535
use std:: ptr;
541
536
use std:: mem;
542
537
@@ -548,7 +543,7 @@ pub mod leusize {
548
543
let ptr_out = dst. as_mut_ptr ( ) ;
549
544
unsafe {
550
545
ptr:: copy_nonoverlapping (
551
- ptr_out , src. as_ptr ( ) , nbytes) ;
546
+ src. as_ptr ( ) , ptr_out , nbytes) ;
552
547
( * ( ptr_out as * const u64 ) ) . to_le ( )
553
548
}
554
549
}
@@ -561,15 +556,14 @@ pub mod leusize {
561
556
// n.b. https://github.com/rust-lang/rust/issues/22776
562
557
let bytes: [ u8 ; 8 ] = mem:: transmute :: < _ , [ u8 ; 8 ] > ( src. to_le ( ) ) ;
563
558
ptr:: copy_nonoverlapping (
564
- dst . as_mut_ptr ( ) , ( & bytes[ ..nbytes] ) . as_ptr ( ) , nbytes) ;
559
+ ( & bytes[ ..nbytes] ) . as_ptr ( ) , dst . as_mut_ptr ( ) , nbytes) ;
565
560
}
566
561
}
567
562
}
568
563
569
564
570
565
macro_rules! mod_odd_impls {
571
566
( $I: ident, $T: ident, $S: ident, $Bytes: expr, $DFunc: ident, $EMeth: ident, $E: expr, $NotE: expr) => {
572
- use std:: num:: Int ;
573
567
use std:: ptr;
574
568
use std:: mem;
575
569
@@ -578,7 +572,7 @@ macro_rules! mod_odd_impls {
578
572
if cfg!( target_endian = $NotE) {
579
573
super :: $T:: swap_memory( dst, src, len) ;
580
574
} else {
581
- ptr:: copy_nonoverlapping( dst , src , len* $Bytes) ;
575
+ ptr:: copy_nonoverlapping( src , dst , len* $Bytes) ;
582
576
}
583
577
}
584
578
@@ -588,8 +582,8 @@ macro_rules! mod_odd_impls {
588
582
assert_eq!( buf. len( ) , $Bytes) ;
589
583
unsafe {
590
584
let mut tmp: $S = mem:: uninitialized( ) ;
591
- ptr:: copy_nonoverlapping( & mut tmp as * mut _ as * mut u8 , buf . as_ptr ( ) , $Bytes) ;
592
- Int :: $DFunc( tmp)
585
+ ptr:: copy_nonoverlapping( buf . as_ptr ( ) , & mut tmp as * mut _ as * mut u8 , $Bytes) ;
586
+ $S :: $DFunc( tmp)
593
587
}
594
588
}
595
589
@@ -608,7 +602,7 @@ macro_rules! mod_odd_impls {
608
602
assert_eq!( dst. len( ) , $Bytes) ;
609
603
unsafe {
610
604
let tmp: $S = src. $EMeth( ) ;
611
- ptr:: copy_nonoverlapping( dst . as_mut_ptr ( ) , & tmp as * const _ as * const u8 , $Bytes) ;
605
+ ptr:: copy_nonoverlapping( & tmp as * const _ as * const u8 , dst . as_mut_ptr ( ) , $Bytes) ;
612
606
}
613
607
}
614
608
@@ -626,7 +620,6 @@ macro_rules! mod_odd_impls {
626
620
627
621
macro_rules! mod_std_impls {
628
622
( $I: ident, $T: ident, $Bytes: expr, $DFunc: ident, $EMeth: ident, $E: expr, $NotE: expr) => {
629
- use std:: num:: Int ;
630
623
use std:: ptr;
631
624
use std:: mem;
632
625
@@ -635,7 +628,7 @@ macro_rules! mod_std_impls {
635
628
if cfg!( target_endian = $NotE) {
636
629
super :: $T:: swap_memory( dst, src, len) ;
637
630
} else {
638
- ptr:: copy_nonoverlapping( dst , src , len* $Bytes) ;
631
+ ptr:: copy_nonoverlapping( src , dst , len* $Bytes) ;
639
632
}
640
633
}
641
634
@@ -645,8 +638,8 @@ macro_rules! mod_std_impls {
645
638
assert_eq!( buf. len( ) , $Bytes) ;
646
639
unsafe {
647
640
let mut tmp: $T = mem:: uninitialized( ) ;
648
- ptr:: copy_nonoverlapping( & mut tmp as * mut _ as * mut u8 , buf . as_ptr ( ) , $Bytes) ;
649
- Int :: $DFunc( tmp)
641
+ ptr:: copy_nonoverlapping( buf . as_ptr ( ) , & mut tmp as * mut _ as * mut u8 , $Bytes) ;
642
+ $T :: $DFunc( tmp)
650
643
}
651
644
}
652
645
@@ -665,7 +658,7 @@ macro_rules! mod_std_impls {
665
658
assert_eq!( dst. len( ) , $Bytes) ;
666
659
unsafe {
667
660
let tmp: $T = src. $EMeth( ) ;
668
- ptr:: copy_nonoverlapping( dst . as_mut_ptr ( ) , & tmp as * const _ as * const u8 , $Bytes) ;
661
+ ptr:: copy_nonoverlapping( & tmp as * const _ as * const u8 , dst . as_mut_ptr ( ) , $Bytes) ;
669
662
}
670
663
}
671
664
0 commit comments