edit_xlsx/
result.rs

1use std::{error, fmt, io};
2use quick_xml::DeError;
3use zip::result::ZipError;
4
5pub type CellResult<T> = Result<T, CellError>;
6#[derive(Debug)]
7pub enum CellError {
8    CellNotFound
9}
10
11impl fmt::Display for CellError {
12    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
13        match *self {
14            CellError::CellNotFound => write!(f, "Cell not found"),
15        }
16    }
17}
18
19impl error::Error for CellError {
20    fn source(&self) -> Option<&(dyn error::Error + 'static)> {
21        match *self {
22            CellError::CellNotFound => None,
23        }
24    }
25}
26
27pub type RowResult<T> = Result<T, RowError>;
28#[derive(Debug)]
29pub enum RowError {
30    RowNotFound,
31    CellError(CellError),
32}
33
34impl fmt::Display for RowError {
35    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
36        match *self {
37            RowError::RowNotFound => write!(f, "Row not found"),
38            RowError::CellError(ref err) => write!(f, "Cell Error: {:?}", err),
39        }
40    }
41}
42
43impl error::Error for RowError {
44    fn source(&self) -> Option<&(dyn error::Error + 'static)> {
45        match *self {
46            RowError::RowNotFound => None,
47            RowError::CellError(ref err) => Some(err),
48        }
49    }
50}
51
52
53impl From<CellError> for RowError { fn from(err: CellError) -> RowError { RowError::CellError(err) } }
54
55pub type ColResult<T> = Result<T, ColError>;
56#[derive(Debug)]
57pub enum ColError {
58    ColNotFound,
59}
60
61impl fmt::Display for ColError {
62    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
63        match *self {
64            ColError::ColNotFound => write!(f, "Column not found"),
65        }
66    }
67}
68
69impl error::Error for ColError {
70    fn source(&self) -> Option<&(dyn error::Error + 'static)> {
71        match *self {
72            ColError::ColNotFound => None,
73        }
74    }
75}
76
77pub type WorkSheetResult<T> = Result<T, WorkSheetError>;
78#[derive(Debug)]
79pub enum WorkSheetError {
80    Io(io::Error),
81    DeError(DeError),
82    ZipError(ZipError),
83    FileNotFound,
84    RowError(RowError),
85    ColError(ColError),
86    DuplicatedSheets,
87    FormatError,
88}
89
90
91impl fmt::Display for WorkSheetError {
92    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
93        match *self {
94            WorkSheetError::Io(ref err) => write!(f, "I/O Error: {:?}", err),
95            WorkSheetError::DeError(ref err) => write!(f, "Deserialization Error: {:?}", err),
96            WorkSheetError::ZipError(ref err) => write!(f, "ZIP File Error: {:?}", err),
97            WorkSheetError::FileNotFound => write!(f, "File not found"),
98            WorkSheetError::RowError(ref err) => write!(f, "Row Error: {:?}", err),
99            WorkSheetError::ColError(ref err) => write!(f, "Column Error: {:?}", err),
100            WorkSheetError::DuplicatedSheets => write!(f, "Duplicated Sheets"),
101            WorkSheetError::FormatError => write!(f, "Format Error"),
102        }
103    }
104}
105
106impl error::Error for WorkSheetError {
107    fn source(&self) -> Option<&(dyn error::Error + 'static)> {
108        match *self {
109            WorkSheetError::Io(ref err) => Some(err),
110            WorkSheetError::DeError(ref err) => Some(err),
111            WorkSheetError::ZipError(ref err) => Some(err),
112            WorkSheetError::FileNotFound => None,
113            WorkSheetError::RowError(ref err) => Some(err),
114            WorkSheetError::ColError(ref err) => Some(err),
115            WorkSheetError::DuplicatedSheets => None,
116            WorkSheetError::FormatError => None,
117        }
118    }
119}
120
121impl From<DeError> for WorkSheetError { fn from(err: DeError) -> WorkSheetError { WorkSheetError::DeError(err) } }
122impl From<io::Error> for WorkSheetError { fn from(err: io::Error) -> WorkSheetError {
123        WorkSheetError::Io(err)
124    } }
125impl From<RowError> for WorkSheetError { fn from(err: RowError) -> WorkSheetError { WorkSheetError::RowError(err) } }
126impl From<ColError> for WorkSheetError { fn from(err: ColError) -> WorkSheetError { WorkSheetError::ColError(err) } }
127
128pub type WorkbookResult<T> = Result<T, WorkbookError>;
129#[derive(Debug)]
130pub enum WorkbookError {
131    Io(io::Error),
132    ZipError(ZipError),
133    SheetError(WorkSheetError),
134    FileNotFound,
135    RelationshipError(RelationshipError),
136}
137
138
139
140impl fmt::Display for WorkbookError {
141    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
142        match *self {
143            WorkbookError::Io(ref err) => write!(f, "I/O Error: {:?}", err),
144            WorkbookError::ZipError(ref err) => write!(f, "ZIP File Error: {:?}", err),
145            WorkbookError::SheetError(ref err) => write!(f, "Worksheet Error: {:?}", err),
146            WorkbookError::FileNotFound => write!(f, "File not found"),
147            WorkbookError::RelationshipError(ref err) => write!(f, "Relationship Error: {:?}", err),
148        }
149    }
150}
151
152impl error::Error for WorkbookError {
153    fn source(&self) -> Option<&(dyn error::Error + 'static)> {
154        match *self {
155            WorkbookError::Io(ref err) => Some(err),
156            WorkbookError::ZipError(ref err) => Some(err),
157            WorkbookError::SheetError(ref err) => Some(err),
158            WorkbookError::FileNotFound => None,  // No underlying source error
159            WorkbookError::RelationshipError(ref err) => Some(err),
160        }
161    }
162}
163
164impl From<io::Error> for WorkbookError {
165    fn from(err: io::Error) -> WorkbookError {
166        WorkbookError::Io(err)
167    }
168}
169
170impl From<ZipError> for WorkbookError {
171    fn from(err: ZipError) -> WorkbookError {
172        WorkbookError::ZipError(err)
173    }
174}
175
176impl From<WorkSheetError> for WorkbookError {
177    fn from(err: WorkSheetError) -> WorkbookError {
178        WorkbookError::SheetError(err)
179    }
180}
181
182pub type RelationshipResult<T> = Result<T, RelationshipError>;
183
184#[derive(Debug)]
185pub enum RelationshipError {
186    UnsupportedNamespace,
187}
188
189impl fmt::Display for RelationshipError {
190    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
191        match *self {
192            RelationshipError::UnsupportedNamespace => write!(f, "Unsupported namespace"),
193        }
194    }
195}
196
197impl error::Error for RelationshipError {
198    fn source(&self) -> Option<&(dyn error::Error + 'static)> {
199        None
200    }
201}
202