Skip to content

Commit 577810e

Browse files
committed
Rename the Error variants
1 parent 626691b commit 577810e

File tree

1 file changed

+28
-28
lines changed

1 file changed

+28
-28
lines changed

src/lib.rs

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,13 @@ pub enum Error {
7070
/// The input slice is not properly aligned for the
7171
/// output data type. E.g. for an `u32` output slice
7272
/// the memory must be 4-byte aligned.
73-
WrongAlignment {
73+
AlignmentMismatch {
7474
dst_type: &'static str,
7575
dst_minimum_alignment: usize
7676
},
7777
/// A non-integer number of values from the output
7878
/// type would be in the output slice.
79-
IncompleteNumberOfValues {
79+
LengthMismatch {
8080
dst_type: &'static str,
8181
src_slice_size: usize,
8282
dst_type_size: usize
@@ -86,7 +86,7 @@ pub enum Error {
8686
impl fmt::Display for Error {
8787
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
8888
match self {
89-
Error::WrongAlignment { dst_type, dst_minimum_alignment } => {
89+
Error::AlignmentMismatch { dst_type, dst_minimum_alignment } => {
9090
write!(
9191
f,
9292
"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 {
9595
dst_type
9696
)?;
9797
},
98-
Error::IncompleteNumberOfValues { dst_type, src_slice_size, dst_type_size } => {
98+
Error::LengthMismatch { dst_type, src_slice_size, dst_type_size } => {
9999
write!(
100100
f,
101101
"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 {
130130
use self::Error::*;
131131

132132
match *self {
133-
WrongAlignment { .. } => "Wrong Alignment",
134-
IncompleteNumberOfValues { .. } => "Incomplete Number of Values",
133+
AlignmentMismatch { .. } => "Alignment Mismatch",
134+
LengthMismatch { .. } => "Length Mismatch",
135135
}
136136
}
137137
}
@@ -140,7 +140,7 @@ fn check_constraints<U>(data: &[u8]) -> Result<usize, Error> {
140140
let alignment = mem::align_of::<U>();
141141

142142
if (data.as_ptr() as usize) % alignment != 0 {
143-
let err = Error::WrongAlignment {
143+
let err = Error::AlignmentMismatch {
144144
dst_type: type_name::<U>(),
145145
dst_minimum_alignment: alignment
146146
};
@@ -149,7 +149,7 @@ fn check_constraints<U>(data: &[u8]) -> Result<usize, Error> {
149149

150150
let size_out = mem::size_of::<U>();
151151
if data.len() % size_out != 0 {
152-
let err = Error::IncompleteNumberOfValues {
152+
let err = Error::LengthMismatch {
153153
dst_type: type_name::<U>(),
154154
src_slice_size: data.len(),
155155
dst_type_size: size_out
@@ -456,7 +456,7 @@ mod tests {
456456

457457
assert_eq!(
458458
(&bytes[1..]).as_slice_of::<u16>(),
459-
Err(Error::WrongAlignment {
459+
Err(Error::AlignmentMismatch {
460460
dst_type: type_name::<u16>(),
461461
dst_minimum_alignment: mem::align_of::<u16>()
462462
})
@@ -478,7 +478,7 @@ mod tests {
478478
}
479479
assert_eq!(
480480
(&bytes[0..15]).as_slice_of::<u16>(),
481-
Err(Error::IncompleteNumberOfValues {
481+
Err(Error::LengthMismatch {
482482
dst_type: type_name::<u16>(),
483483
src_slice_size: 15,
484484
dst_type_size: mem::size_of::<u16>()
@@ -515,14 +515,14 @@ mod tests {
515515

516516
assert_eq!(
517517
(&bytes[1..]).as_slice_of::<u32>(),
518-
Err(Error::WrongAlignment {
518+
Err(Error::AlignmentMismatch {
519519
dst_type: type_name::<u32>(),
520520
dst_minimum_alignment: mem::align_of::<u32>()
521521
})
522522
);
523523
assert_eq!(
524524
(&bytes[0..15]).as_slice_of::<u32>(),
525-
Err(Error::IncompleteNumberOfValues {
525+
Err(Error::LengthMismatch {
526526
dst_type: type_name::<u32>(),
527527
src_slice_size: 15,
528528
dst_type_size: mem::size_of::<u32>()
@@ -544,14 +544,14 @@ mod tests {
544544

545545
assert_eq!(
546546
(&bytes[1..]).as_slice_of::<u64>(),
547-
Err(Error::WrongAlignment {
547+
Err(Error::AlignmentMismatch {
548548
dst_type: type_name::<u64>(),
549549
dst_minimum_alignment: mem::align_of::<u64>()
550550
})
551551
);
552552
assert_eq!(
553553
(&bytes[0..15]).as_slice_of::<u64>(),
554-
Err(Error::IncompleteNumberOfValues {
554+
Err(Error::LengthMismatch {
555555
dst_type: type_name::<u64>(),
556556
src_slice_size: 15,
557557
dst_type_size: mem::size_of::<u64>()
@@ -585,14 +585,14 @@ mod tests {
585585

586586
assert_eq!(
587587
(&bytes[1..]).as_slice_of::<f32>(),
588-
Err(Error::WrongAlignment {
588+
Err(Error::AlignmentMismatch {
589589
dst_type: type_name::<f32>(),
590590
dst_minimum_alignment: mem::align_of::<f32>()
591591
})
592592
);
593593
assert_eq!(
594594
(&bytes[0..15]).as_slice_of::<f32>(),
595-
Err(Error::IncompleteNumberOfValues {
595+
Err(Error::LengthMismatch {
596596
dst_type: type_name::<f32>(),
597597
src_slice_size: 15,
598598
dst_type_size: mem::size_of::<f32>()
@@ -626,14 +626,14 @@ mod tests {
626626

627627
assert_eq!(
628628
(&bytes[1..]).as_slice_of::<f64>(),
629-
Err(Error::WrongAlignment {
629+
Err(Error::AlignmentMismatch {
630630
dst_type: type_name::<f64>(),
631631
dst_minimum_alignment: mem::align_of::<f64>()
632632
})
633633
);
634634
assert_eq!(
635635
(&bytes[0..15]).as_slice_of::<f64>(),
636-
Err(Error::IncompleteNumberOfValues {
636+
Err(Error::LengthMismatch {
637637
dst_type: type_name::<f64>(),
638638
src_slice_size: 15,
639639
dst_type_size: mem::size_of::<f64>()
@@ -656,14 +656,14 @@ mod tests {
656656

657657
assert_eq!(
658658
(&mut bytes[1..]).as_mut_slice_of::<u16>(),
659-
Err(Error::WrongAlignment {
659+
Err(Error::AlignmentMismatch {
660660
dst_type: type_name::<u16>(),
661661
dst_minimum_alignment: mem::align_of::<u16>()
662662
})
663663
);
664664
assert_eq!(
665665
(&mut bytes[0..15]).as_mut_slice_of::<u16>(),
666-
Err(Error::IncompleteNumberOfValues {
666+
Err(Error::LengthMismatch {
667667
dst_type: type_name::<u16>(),
668668
src_slice_size: 15,
669669
dst_type_size: mem::size_of::<u16>()
@@ -685,14 +685,14 @@ mod tests {
685685

686686
assert_eq!(
687687
(&bytes[1..]).as_slice_of::<u16>(),
688-
Err(Error::WrongAlignment {
688+
Err(Error::AlignmentMismatch {
689689
dst_type: type_name::<u16>(),
690690
dst_minimum_alignment: mem::align_of::<u16>()
691691
})
692692
);
693693
assert_eq!(
694694
(&bytes[0..15]).as_slice_of::<u16>(),
695-
Err(Error::IncompleteNumberOfValues {
695+
Err(Error::LengthMismatch {
696696
dst_type: type_name::<u16>(),
697697
src_slice_size: 15,
698698
dst_type_size: mem::size_of::<u16>()
@@ -715,14 +715,14 @@ mod tests {
715715

716716
assert_eq!(
717717
(&mut bytes[1..]).as_mut_slice_of::<u16>(),
718-
Err(Error::WrongAlignment {
718+
Err(Error::AlignmentMismatch {
719719
dst_type: type_name::<u16>(),
720720
dst_minimum_alignment: mem::align_of::<u16>()
721721
})
722722
);
723723
assert_eq!(
724724
(&mut bytes[0..15]).as_mut_slice_of::<u16>(),
725-
Err(Error::IncompleteNumberOfValues {
725+
Err(Error::LengthMismatch {
726726
dst_type: type_name::<u16>(),
727727
src_slice_size: 15,
728728
dst_type_size: mem::size_of::<u16>()
@@ -744,14 +744,14 @@ mod tests {
744744

745745
assert_eq!(
746746
(&bytes[1..]).as_slice_of::<u16>(),
747-
Err(Error::WrongAlignment {
747+
Err(Error::AlignmentMismatch {
748748
dst_type: type_name::<u16>(),
749749
dst_minimum_alignment: mem::align_of::<u16>()
750750
})
751751
);
752752
assert_eq!(
753753
(&bytes[0..15]).as_slice_of::<u16>(),
754-
Err(Error::IncompleteNumberOfValues {
754+
Err(Error::LengthMismatch {
755755
dst_type: type_name::<u16>(),
756756
src_slice_size: 15,
757757
dst_type_size: mem::size_of::<u16>()
@@ -774,14 +774,14 @@ mod tests {
774774

775775
assert_eq!(
776776
(&mut bytes[1..]).as_mut_slice_of::<u16>(),
777-
Err(Error::WrongAlignment {
777+
Err(Error::AlignmentMismatch {
778778
dst_type: type_name::<u16>(),
779779
dst_minimum_alignment: mem::align_of::<u16>()
780780
})
781781
);
782782
assert_eq!(
783783
(&mut bytes[0..15]).as_mut_slice_of::<u16>(),
784-
Err(Error::IncompleteNumberOfValues {
784+
Err(Error::LengthMismatch {
785785
dst_type: type_name::<u16>(),
786786
src_slice_size: 15,
787787
dst_type_size: mem::size_of::<u16>()

0 commit comments

Comments
 (0)