use std::fmt;
#[derive(Clone, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub enum Error {
Zip(ZipFault),
Limit(Limit),
Xml(f_office_xml::Error),
NoMainDocument,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub enum ZipFault {
Archive,
Entry,
Name,
Read,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub enum Limit {
Entries,
PartSize,
TotalSize,
Ratio,
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Zip(fault) => write!(f, "unreadable ZIP package: {fault}"),
Self::Limit(limit) => write!(f, "package breaks the limit on {limit}"),
Self::Xml(_) => f.write_str("bad relationships part"),
Self::NoMainDocument => f.write_str("package has no main document"),
}
}
}
impl fmt::Display for ZipFault {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(match self {
Self::Archive => "its central directory does not read",
Self::Entry => "an entry of its central directory does not read",
Self::Name => "the name of an entry does not read",
Self::Read => "the data of an entry does not read",
})
}
}
impl fmt::Display for Limit {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(match self {
Self::Entries => "the number of entries",
Self::PartSize => "the size of a part",
Self::TotalSize => "the total size",
Self::Ratio => "the compression ratio",
})
}
}
impl std::error::Error for Error {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
Self::Xml(error) => Some(error),
Self::Zip(_) | Self::Limit(_) | Self::NoMainDocument => None,
}
}
}