2018-03-19 07:35:00 -05:00
|
|
|
#[cfg(any(test, not(feature = "no_std")))]
|
|
|
|
use std::io;
|
|
|
|
|
2018-03-18 12:11:58 -05:00
|
|
|
/// The set of all possible errors
|
2018-03-19 07:35:00 -05:00
|
|
|
#[derive(Debug)]
|
2018-03-18 12:34:26 -05:00
|
|
|
pub enum Error {
|
|
|
|
BadMagic(u16),
|
|
|
|
OutOfBounds(usize),
|
2018-03-20 06:30:36 -05:00
|
|
|
AddressOutOfBounds(usize, usize, usize),
|
2018-03-18 12:34:26 -05:00
|
|
|
BadBlockGroupCount(u32, u32),
|
2018-03-19 07:35:00 -05:00
|
|
|
#[cfg(any(test, not(feature = "no_std")))]
|
|
|
|
Io(io::Error),
|
2018-03-18 12:11:58 -05:00
|
|
|
}
|
2018-03-19 07:28:18 -05:00
|
|
|
|
|
|
|
impl From<Infallible> for Error {
|
|
|
|
fn from(_: Infallible) -> Error {
|
|
|
|
unreachable!()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-19 07:35:00 -05:00
|
|
|
#[cfg(any(test, not(feature = "no_std")))]
|
|
|
|
impl From<io::Error> for Error {
|
|
|
|
fn from(err: io::Error) -> Error {
|
|
|
|
Error::Io(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-19 11:23:45 -05:00
|
|
|
impl PartialEq for Error {
|
|
|
|
fn eq(&self, rhs: &Error) -> bool {
|
|
|
|
match (self, rhs) {
|
|
|
|
(&Error::BadMagic(a), &Error::BadMagic(b)) => a == b,
|
|
|
|
(&Error::OutOfBounds(a), &Error::OutOfBounds(b)) => a == b,
|
|
|
|
(
|
|
|
|
&Error::BadBlockGroupCount(a1, a2),
|
|
|
|
&Error::BadBlockGroupCount(b1, b2),
|
|
|
|
) => a1 == b1 && a2 == b2,
|
|
|
|
_ => false,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn ne(&self, rhs: &Error) -> bool {
|
|
|
|
match (self, rhs) {
|
|
|
|
(&Error::BadMagic(a), &Error::BadMagic(b)) => a != b,
|
|
|
|
(&Error::OutOfBounds(a), &Error::OutOfBounds(b)) => a != b,
|
|
|
|
(
|
|
|
|
&Error::BadBlockGroupCount(a1, a2),
|
|
|
|
&Error::BadBlockGroupCount(b1, b2),
|
|
|
|
) => a1 != b1 || a2 != b2,
|
|
|
|
_ => false,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-19 07:28:18 -05:00
|
|
|
pub enum Infallible {}
|