@@ -70,13 +70,13 @@ pub enum Error {
70
70
/// The input slice is not properly aligned for the
71
71
/// output data type. E.g. for an `u32` output slice
72
72
/// the memory must be 4-byte aligned.
73
- WrongAlignment {
73
+ AlignmentMismatch {
74
74
dst_type : & ' static str ,
75
75
dst_minimum_alignment : usize
76
76
} ,
77
77
/// A non-integer number of values from the output
78
78
/// type would be in the output slice.
79
- IncompleteNumberOfValues {
79
+ LengthMismatch {
80
80
dst_type : & ' static str ,
81
81
src_slice_size : usize ,
82
82
dst_type_size : usize
@@ -86,7 +86,7 @@ pub enum Error {
86
86
impl fmt:: Display for Error {
87
87
fn fmt ( & self , f : & mut fmt:: Formatter ) -> Result < ( ) , fmt:: Error > {
88
88
match self {
89
- Error :: WrongAlignment { dst_type, dst_minimum_alignment } => {
89
+ Error :: AlignmentMismatch { dst_type, dst_minimum_alignment } => {
90
90
write ! (
91
91
f,
92
92
"cannot cast a &[u8] into a &[{}]: the slice's address is not divisible by the minimum alignment ({}) of {}" ,
@@ -95,7 +95,7 @@ impl fmt::Display for Error {
95
95
dst_type
96
96
) ?;
97
97
} ,
98
- Error :: IncompleteNumberOfValues { dst_type, src_slice_size, dst_type_size } => {
98
+ Error :: LengthMismatch { dst_type, src_slice_size, dst_type_size } => {
99
99
write ! (
100
100
f,
101
101
"cannot cast a &[u8] into a &[{}]: the size ({}) of the slice is not divisible by the size ({}) of {}" ,
@@ -130,8 +130,8 @@ impl StdError for Error {
130
130
use self :: Error :: * ;
131
131
132
132
match * self {
133
- WrongAlignment { .. } => "Wrong Alignment" ,
134
- IncompleteNumberOfValues { .. } => "Incomplete Number of Values " ,
133
+ AlignmentMismatch { .. } => "Alignment Mismatch " ,
134
+ LengthMismatch { .. } => "Length Mismatch " ,
135
135
}
136
136
}
137
137
}
@@ -140,7 +140,7 @@ fn check_constraints<U>(data: &[u8]) -> Result<usize, Error> {
140
140
let alignment = mem:: align_of :: < U > ( ) ;
141
141
142
142
if ( data. as_ptr ( ) as usize ) % alignment != 0 {
143
- let err = Error :: WrongAlignment {
143
+ let err = Error :: AlignmentMismatch {
144
144
dst_type : type_name :: < U > ( ) ,
145
145
dst_minimum_alignment : alignment
146
146
} ;
@@ -149,7 +149,7 @@ fn check_constraints<U>(data: &[u8]) -> Result<usize, Error> {
149
149
150
150
let size_out = mem:: size_of :: < U > ( ) ;
151
151
if data. len ( ) % size_out != 0 {
152
- let err = Error :: IncompleteNumberOfValues {
152
+ let err = Error :: LengthMismatch {
153
153
dst_type : type_name :: < U > ( ) ,
154
154
src_slice_size : data. len ( ) ,
155
155
dst_type_size : size_out
@@ -456,7 +456,7 @@ mod tests {
456
456
457
457
assert_eq ! (
458
458
( & bytes[ 1 ..] ) . as_slice_of:: <u16 >( ) ,
459
- Err ( Error :: WrongAlignment {
459
+ Err ( Error :: AlignmentMismatch {
460
460
dst_type: type_name:: <u16 >( ) ,
461
461
dst_minimum_alignment: mem:: align_of:: <u16 >( )
462
462
} )
@@ -478,7 +478,7 @@ mod tests {
478
478
}
479
479
assert_eq ! (
480
480
( & bytes[ 0 ..15 ] ) . as_slice_of:: <u16 >( ) ,
481
- Err ( Error :: IncompleteNumberOfValues {
481
+ Err ( Error :: LengthMismatch {
482
482
dst_type: type_name:: <u16 >( ) ,
483
483
src_slice_size: 15 ,
484
484
dst_type_size: mem:: size_of:: <u16 >( )
@@ -515,14 +515,14 @@ mod tests {
515
515
516
516
assert_eq ! (
517
517
( & bytes[ 1 ..] ) . as_slice_of:: <u32 >( ) ,
518
- Err ( Error :: WrongAlignment {
518
+ Err ( Error :: AlignmentMismatch {
519
519
dst_type: type_name:: <u32 >( ) ,
520
520
dst_minimum_alignment: mem:: align_of:: <u32 >( )
521
521
} )
522
522
) ;
523
523
assert_eq ! (
524
524
( & bytes[ 0 ..15 ] ) . as_slice_of:: <u32 >( ) ,
525
- Err ( Error :: IncompleteNumberOfValues {
525
+ Err ( Error :: LengthMismatch {
526
526
dst_type: type_name:: <u32 >( ) ,
527
527
src_slice_size: 15 ,
528
528
dst_type_size: mem:: size_of:: <u32 >( )
@@ -544,14 +544,14 @@ mod tests {
544
544
545
545
assert_eq ! (
546
546
( & bytes[ 1 ..] ) . as_slice_of:: <u64 >( ) ,
547
- Err ( Error :: WrongAlignment {
547
+ Err ( Error :: AlignmentMismatch {
548
548
dst_type: type_name:: <u64 >( ) ,
549
549
dst_minimum_alignment: mem:: align_of:: <u64 >( )
550
550
} )
551
551
) ;
552
552
assert_eq ! (
553
553
( & bytes[ 0 ..15 ] ) . as_slice_of:: <u64 >( ) ,
554
- Err ( Error :: IncompleteNumberOfValues {
554
+ Err ( Error :: LengthMismatch {
555
555
dst_type: type_name:: <u64 >( ) ,
556
556
src_slice_size: 15 ,
557
557
dst_type_size: mem:: size_of:: <u64 >( )
@@ -585,14 +585,14 @@ mod tests {
585
585
586
586
assert_eq ! (
587
587
( & bytes[ 1 ..] ) . as_slice_of:: <f32 >( ) ,
588
- Err ( Error :: WrongAlignment {
588
+ Err ( Error :: AlignmentMismatch {
589
589
dst_type: type_name:: <f32 >( ) ,
590
590
dst_minimum_alignment: mem:: align_of:: <f32 >( )
591
591
} )
592
592
) ;
593
593
assert_eq ! (
594
594
( & bytes[ 0 ..15 ] ) . as_slice_of:: <f32 >( ) ,
595
- Err ( Error :: IncompleteNumberOfValues {
595
+ Err ( Error :: LengthMismatch {
596
596
dst_type: type_name:: <f32 >( ) ,
597
597
src_slice_size: 15 ,
598
598
dst_type_size: mem:: size_of:: <f32 >( )
@@ -626,14 +626,14 @@ mod tests {
626
626
627
627
assert_eq ! (
628
628
( & bytes[ 1 ..] ) . as_slice_of:: <f64 >( ) ,
629
- Err ( Error :: WrongAlignment {
629
+ Err ( Error :: AlignmentMismatch {
630
630
dst_type: type_name:: <f64 >( ) ,
631
631
dst_minimum_alignment: mem:: align_of:: <f64 >( )
632
632
} )
633
633
) ;
634
634
assert_eq ! (
635
635
( & bytes[ 0 ..15 ] ) . as_slice_of:: <f64 >( ) ,
636
- Err ( Error :: IncompleteNumberOfValues {
636
+ Err ( Error :: LengthMismatch {
637
637
dst_type: type_name:: <f64 >( ) ,
638
638
src_slice_size: 15 ,
639
639
dst_type_size: mem:: size_of:: <f64 >( )
@@ -656,14 +656,14 @@ mod tests {
656
656
657
657
assert_eq ! (
658
658
( & mut bytes[ 1 ..] ) . as_mut_slice_of:: <u16 >( ) ,
659
- Err ( Error :: WrongAlignment {
659
+ Err ( Error :: AlignmentMismatch {
660
660
dst_type: type_name:: <u16 >( ) ,
661
661
dst_minimum_alignment: mem:: align_of:: <u16 >( )
662
662
} )
663
663
) ;
664
664
assert_eq ! (
665
665
( & mut bytes[ 0 ..15 ] ) . as_mut_slice_of:: <u16 >( ) ,
666
- Err ( Error :: IncompleteNumberOfValues {
666
+ Err ( Error :: LengthMismatch {
667
667
dst_type: type_name:: <u16 >( ) ,
668
668
src_slice_size: 15 ,
669
669
dst_type_size: mem:: size_of:: <u16 >( )
@@ -685,14 +685,14 @@ mod tests {
685
685
686
686
assert_eq ! (
687
687
( & bytes[ 1 ..] ) . as_slice_of:: <u16 >( ) ,
688
- Err ( Error :: WrongAlignment {
688
+ Err ( Error :: AlignmentMismatch {
689
689
dst_type: type_name:: <u16 >( ) ,
690
690
dst_minimum_alignment: mem:: align_of:: <u16 >( )
691
691
} )
692
692
) ;
693
693
assert_eq ! (
694
694
( & bytes[ 0 ..15 ] ) . as_slice_of:: <u16 >( ) ,
695
- Err ( Error :: IncompleteNumberOfValues {
695
+ Err ( Error :: LengthMismatch {
696
696
dst_type: type_name:: <u16 >( ) ,
697
697
src_slice_size: 15 ,
698
698
dst_type_size: mem:: size_of:: <u16 >( )
@@ -715,14 +715,14 @@ mod tests {
715
715
716
716
assert_eq ! (
717
717
( & mut bytes[ 1 ..] ) . as_mut_slice_of:: <u16 >( ) ,
718
- Err ( Error :: WrongAlignment {
718
+ Err ( Error :: AlignmentMismatch {
719
719
dst_type: type_name:: <u16 >( ) ,
720
720
dst_minimum_alignment: mem:: align_of:: <u16 >( )
721
721
} )
722
722
) ;
723
723
assert_eq ! (
724
724
( & mut bytes[ 0 ..15 ] ) . as_mut_slice_of:: <u16 >( ) ,
725
- Err ( Error :: IncompleteNumberOfValues {
725
+ Err ( Error :: LengthMismatch {
726
726
dst_type: type_name:: <u16 >( ) ,
727
727
src_slice_size: 15 ,
728
728
dst_type_size: mem:: size_of:: <u16 >( )
@@ -744,14 +744,14 @@ mod tests {
744
744
745
745
assert_eq ! (
746
746
( & bytes[ 1 ..] ) . as_slice_of:: <u16 >( ) ,
747
- Err ( Error :: WrongAlignment {
747
+ Err ( Error :: AlignmentMismatch {
748
748
dst_type: type_name:: <u16 >( ) ,
749
749
dst_minimum_alignment: mem:: align_of:: <u16 >( )
750
750
} )
751
751
) ;
752
752
assert_eq ! (
753
753
( & bytes[ 0 ..15 ] ) . as_slice_of:: <u16 >( ) ,
754
- Err ( Error :: IncompleteNumberOfValues {
754
+ Err ( Error :: LengthMismatch {
755
755
dst_type: type_name:: <u16 >( ) ,
756
756
src_slice_size: 15 ,
757
757
dst_type_size: mem:: size_of:: <u16 >( )
@@ -774,14 +774,14 @@ mod tests {
774
774
775
775
assert_eq ! (
776
776
( & mut bytes[ 1 ..] ) . as_mut_slice_of:: <u16 >( ) ,
777
- Err ( Error :: WrongAlignment {
777
+ Err ( Error :: AlignmentMismatch {
778
778
dst_type: type_name:: <u16 >( ) ,
779
779
dst_minimum_alignment: mem:: align_of:: <u16 >( )
780
780
} )
781
781
) ;
782
782
assert_eq ! (
783
783
( & mut bytes[ 0 ..15 ] ) . as_mut_slice_of:: <u16 >( ) ,
784
- Err ( Error :: IncompleteNumberOfValues {
784
+ Err ( Error :: LengthMismatch {
785
785
dst_type: type_name:: <u16 >( ) ,
786
786
src_slice_size: 15 ,
787
787
dst_type_size: mem:: size_of:: <u16 >( )
0 commit comments