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.
This commit is contained in:
Myrddin Dundragon 2018-01-08 23:36:15 -05:00
parent 12096a5136
commit 27a3195bea

View File

@ -7,11 +7,17 @@ use weave::Error;
#[derive(Copy, Clone, Eq, PartialEq)] #[derive(Copy, Clone, Eq, PartialEq)]
pub enum ConversionError 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. /// There were not enough bytes to create the desired type.
TooFewBytes, TooFewBytes,
/// There were to many bytes to create the desired type. /// There were to many bytes to create the desired type.
TooManyBytes TooManyBytes,
} }
@ -22,6 +28,16 @@ impl Error for ConversionError
{ {
match *self 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 => ConversionError::TooFewBytes =>
{ {
"Not enough bytes of data were provided \ "Not enough bytes of data were provided \
@ -62,6 +78,16 @@ impl ::std::fmt::Display for ConversionError
{ {
match *self match *self
{ {
ConversionError::CorruptionDetected =>
{
write!(f, "Byte Conversion Error: CorruptionDetected")
}
ConversionError::InvalidValue =>
{
write!(f, "Byte Conversion Error: InvalidValue")
}
ConversionError::TooFewBytes => ConversionError::TooFewBytes =>
{ {
write!(f, "Byte Conversion Error: TooFewBytes") write!(f, "Byte Conversion Error: TooFewBytes")