From 27a3195bea4b1ffb46e45654549dd219d9710f13 Mon Sep 17 00:00:00 2001 From: Jason Smith Date: Mon, 8 Jan 2018 23:36:15 -0500 Subject: [PATCH] Added a couple new Errors that can be supplied during transmutation. Added an error for a corruption detection of the given bytes. This was added so that an inproper CRC code when reading a PNG file could throw an Error. Added an error for an invalid value being transmuted from the given bytes. This was added so that an Error can be thrown when a value outside of a given range is parsed. --- src/conversion_error.rs | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/src/conversion_error.rs b/src/conversion_error.rs index 85a136d..fe73ed8 100644 --- a/src/conversion_error.rs +++ b/src/conversion_error.rs @@ -7,11 +7,17 @@ use weave::Error; #[derive(Copy, Clone, Eq, PartialEq)] pub enum ConversionError { + /// A corruption of the binary data has been detected. + CorruptionDetected, + + /// An invalid value was detected. + InvalidValue, + /// There were not enough bytes to create the desired type. TooFewBytes, /// There were to many bytes to create the desired type. - TooManyBytes + TooManyBytes, } @@ -22,6 +28,16 @@ impl Error for ConversionError { match *self { + ConversionError::CorruptionDetected => + { + "A corruption of the byte data was detected." + } + + ConversionError::InvalidValue => + { + "An invalid value was transmuted from the given byte data." + } + ConversionError::TooFewBytes => { "Not enough bytes of data were provided \ @@ -62,6 +78,16 @@ impl ::std::fmt::Display for ConversionError { match *self { + ConversionError::CorruptionDetected => + { + write!(f, "Byte Conversion Error: CorruptionDetected") + } + + ConversionError::InvalidValue => + { + write!(f, "Byte Conversion Error: InvalidValue") + } + ConversionError::TooFewBytes => { write!(f, "Byte Conversion Error: TooFewBytes")