#[derive(Debug)]
pub enum CascError {
FileNotFound(String),
FileCorrupted(String),
InvalidData(String),
UnsupportedFileType(String),
Io(std::io::Error),
Other(String),
}
impl std::fmt::Display for CascError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
CascError::InvalidData(err) => write!(f, "Invalid data: {}", err),
CascError::FileNotFound(name) => write!(f, "File not found: {}", name),
CascError::FileCorrupted(name) => write!(f, "File is corrupted: {}", name),
CascError::UnsupportedFileType(name) => write!(f, "Unsupported file type: {}", name),
CascError::Io(err) => write!(f, "I/O error: {}", err),
CascError::Other(err) => write!(f, "CASC error: {}", err),
}
}
}
impl std::error::Error for CascError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
CascError::Io(err) => Some(err),
_ => None,
}
}
}
impl From<std::io::Error> for CascError {
fn from(error: std::io::Error) -> Self {
CascError::Io(error)
}
}