This repository has been archived on 2022-02-08. You can view files and clone it, but cannot push or open issues or pull requests.
ext2-rs/src/error.rs

74 lines
1.8 KiB
Rust
Raw Normal View History

2018-03-21 14:40:39 -05:00
use core::fmt::{self, Display};
use alloc::String;
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)]
pub enum Error {
2018-03-21 14:40:39 -05:00
Other(String),
BadMagic {
magic: u16,
},
OutOfBounds {
index: usize,
},
AddressOutOfBounds {
sector: u32,
offset: u32,
size: usize,
},
BadBlockGroupCount {
by_blocks: u32,
by_inodes: u32,
},
2018-03-19 07:35:00 -05:00
#[cfg(any(test, not(feature = "no_std")))]
2018-03-21 14:40:39 -05:00
Io {
inner: io::Error,
},
}
impl Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
Error::Other(ref msg) => write!(f, "{}", msg),
Error::BadMagic {
magic,
} => write!(f, "invalid magic value: {}", magic),
Error::OutOfBounds {
index,
} => write!(f, "index ouf of bounds: {}", index),
Error::AddressOutOfBounds {
sector,
offset,
size,
} => write!(f, "address ouf of bounds: {}:{} with a block size of: {}",
sector, offset, size),
Error::BadBlockGroupCount {
by_blocks,
by_inodes,
} => write!(f, "conflicting block group count data; by blocks: {}, by inodes: {}", by_blocks, by_inodes),
#[cfg(any(test, not(feature = "no_std")))]
Error::Io {
ref inner,
} => write!(f, "io error: {}", inner),
}
}
2018-03-18 12:11:58 -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 {
2018-03-21 14:40:39 -05:00
fn from(inner: io::Error) -> Error {
Error::Io { inner }
2018-03-19 11:23:45 -05:00
}
}
pub enum Infallible {}