use crate::from_err;
use std::{fmt, str::FromStr};
#[derive(Debug, Clone, PartialEq, PartialOrd)]
pub enum CellErrorType {
Div0,
Name,
NA,
Num,
Value,
Ref,
Null,
Data,
}
impl fmt::Display for CellErrorType {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
match *self {
CellErrorType::Div0 => write!(f, "#DIV/0!"),
CellErrorType::NA => write!(f, "#N/A"),
CellErrorType::Name => write!(f, "#NAME?"),
CellErrorType::Null => write!(f, "#NULL!"),
CellErrorType::Num => write!(f, "#NUM!"),
CellErrorType::Ref => write!(f, "#REF!"),
CellErrorType::Value => write!(f, "#VALUE!"),
CellErrorType::Data => write!(f, "#DATA!"),
}
}
}
impl FromStr for CellErrorType {
type Err = XlsxError;
#[inline]
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"#DIV/0!" => Ok(CellErrorType::Div0),
"#N/A" => Ok(CellErrorType::NA),
"#NAME?" => Ok(CellErrorType::Name),
"#NULL!" => Ok(CellErrorType::Null),
"#NUM!" => Ok(CellErrorType::Num),
"#REF!" => Ok(CellErrorType::Ref),
"#VALUE!" => Ok(CellErrorType::Value),
"#DATA!" => Ok(CellErrorType::Data),
_ => Err(XlsxError::CellError(s.into())),
}
}
}
#[derive(Debug)]
pub enum XlsxError {
Io(std::io::Error),
Xml(quick_xml::Error),
Zip(zip::result::ZipError),
Uft8(std::string::FromUtf8Error),
CellError(String),
}
from_err!(std::io::Error, XlsxError, Io);
from_err!(quick_xml::Error, XlsxError, Xml);
from_err!(zip::result::ZipError, XlsxError, Zip);
from_err!(std::string::FromUtf8Error, XlsxError, Uft8);
impl fmt::Display for XlsxError {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
use self::XlsxError::*;
match self {
Io(i) => write!(f, "IoError: {}", i),
Xml(s) => write!(f, "XmlError: {}", s),
Zip(s) => write!(f, "ZipError: {}", s),
Uft8(s) => write!(f, "Uft8Error: {}", s),
CellError(e) => write!(f, "Unsupported cell error value '{e}'"),
}
}
}
impl std::error::Error for XlsxError {}