use std::fmt;
#[derive(Debug)]
pub enum ExcelError {
Io(std::io::Error),
Zip(zip::result::ZipError),
TooManySheets,
RowLimitExceeded,
ColumnLimitExceeded,
HeaderAfterRows,
SheetAlreadyExists,
}
pub type Result<T> = std::result::Result<T, ExcelError>;
impl fmt::Display for ExcelError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Io(e) => write!(f, "IO error: {e}"),
Self::Zip(e) => write!(f, "ZIP error: {e}"),
Self::TooManySheets => {
write!(f, "exceeded maximum sheet count of {}", u16::MAX)
}
Self::RowLimitExceeded => {
write!(f, "exceeded Excel row limit of {}", 1048576)
}
Self::ColumnLimitExceeded => {
write!(f, "exceeded Excel column limit of {}", 16384)
}
Self::HeaderAfterRows => {
write!(f, "you cannot write a header after already writing rows")
}
Self::SheetAlreadyExists => {
write!(f, "a sheet with that name already exists. sheets need to have unique names")
}
}
}
}
impl std::error::Error for ExcelError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
Self::Io(e) => Some(e),
Self::Zip(e) => Some(e),
_ => None,
}
}
}
impl From<std::io::Error> for ExcelError {
fn from(e: std::io::Error) -> Self {
Self::Io(e)
}
}
impl From<zip::result::ZipError> for ExcelError {
fn from(e: zip::result::ZipError) -> Self {
Self::Zip(e)
}
}