use std::fmt;
#[derive(Debug)]
pub enum HwpError {
InvalidFormat(String),
UnsupportedVersion(String),
Io(std::io::Error),
Cfb(String),
CompressionError(String),
ParseError(String),
EncodingError(String),
NotFound(String),
}
impl fmt::Display for HwpError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
HwpError::InvalidFormat(msg) => write!(f, "Invalid file format: {msg}"),
HwpError::UnsupportedVersion(msg) => write!(f, "Unsupported version: {msg}"),
HwpError::Io(e) => write!(f, "IO error: {e}"),
HwpError::Cfb(msg) => write!(f, "CFB error: {msg}"),
HwpError::CompressionError(msg) => write!(f, "Compression error: {msg}"),
HwpError::ParseError(msg) => write!(f, "Parse error: {msg}"),
HwpError::EncodingError(msg) => write!(f, "Encoding error: {msg}"),
HwpError::NotFound(msg) => write!(f, "Not found: {msg}"),
}
}
}
impl std::error::Error for HwpError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
HwpError::Io(e) => Some(e),
_ => None,
}
}
}
impl From<std::io::Error> for HwpError {
fn from(e: std::io::Error) -> Self {
HwpError::Io(e)
}
}
pub type Result<T> = std::result::Result<T, HwpError>;