btrfs_explorer/src/main_error.rs

46 lines
1.0 KiB
Rust

pub struct MainError(pub String);
impl std::error::Error for MainError {}
impl std::fmt::Debug for MainError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", &self.0)
}
}
impl std::fmt::Display for MainError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", &self.0)
}
}
impl From<String> for MainError {
fn from(value: String) -> MainError {
MainError(value)
}
}
impl From<&str> for MainError {
fn from(value: &str) -> MainError {
MainError::from(String::from(value))
}
}
impl From<crate::btrfs_structs::ParseError> for MainError {
fn from(value: crate::btrfs_structs::ParseError) -> MainError {
MainError::from(format!("BTRFS format error: {value}"))
}
}
impl From<std::io::Error> for MainError {
fn from(value: std::io::Error) -> MainError {
MainError::from(format!("IO error: {value}"))
}
}
impl From<std::num::ParseIntError> for MainError {
fn from(value: std::num::ParseIntError) -> MainError {
MainError::from(format!("Not an integer: {value}"))
}
}