1use std::fmt;
2
3#[derive(Debug)]
4pub enum Error {
5 InvalidDocx(String),
6 Zip(zip::result::ZipError),
7 Xml(roxmltree::Error),
8 Pdf(String),
9 Io(std::io::Error),
10}
11
12impl fmt::Display for Error {
13 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
14 match self {
15 Error::InvalidDocx(reason) => write!(f, "not a valid DOCX file: {reason}"),
16 Error::Zip(e) => write!(f, "ZIP error: {e}"),
17 Error::Xml(e) => write!(f, "XML error: {e}"),
18 Error::Pdf(e) => write!(f, "PDF error: {e}"),
19 Error::Io(e) => write!(f, "IO error: {e}"),
20 }
21 }
22}
23
24impl std::error::Error for Error {}
25
26impl From<zip::result::ZipError> for Error {
27 fn from(e: zip::result::ZipError) -> Self {
28 Self::Zip(e)
29 }
30}
31
32impl From<roxmltree::Error> for Error {
33 fn from(e: roxmltree::Error) -> Self {
34 Self::Xml(e)
35 }
36}
37
38impl From<std::io::Error> for Error {
39 fn from(e: std::io::Error) -> Self {
40 Self::Io(e)
41 }
42}