use std::fmt;
#[derive(Debug)]
pub enum Error {
Package(String),
MissingPart(&'static str),
Xml {
part: String,
detail: String,
},
WrongFormat {
found: String,
wanted: &'static str,
},
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Package(detail) => write!(f, "not a readable package: {detail}"),
Self::MissingPart(name) => write!(f, "the package has no {name}"),
Self::Xml { part, detail } => write!(f, "{part} is not well-formed XML: {detail}"),
Self::WrongFormat { found, wanted } => {
write!(f, "this is a {found} package, not a {wanted} one")
}
}
}
}
impl std::error::Error for Error {}
impl From<zip::result::ZipError> for Error {
fn from(e: zip::result::ZipError) -> Self {
Self::Package(e.to_string())
}
}