1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
use std::{fmt, io};
pub type DocimaResult<T> = std::result::Result<T, DocimaError>;
pub type StdResult<T> = std::result::Result<T, Box<dyn std::error::Error>>;
#[derive(Debug)]
#[non_exhaustive]
pub enum DocimaError {
IoError(io::Error),
PngEncodingError(png::EncodingError),
StdError(Box<dyn std::error::Error>),
MissingField(String),
Custom(String),
}
impl fmt::Display for DocimaError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
use DocimaError::*;
match self {
IoError(err) => write!(f, "{}", err),
PngEncodingError(err) => write!(f, "{}", err),
StdError(err) => write!(f, "{}", err),
MissingField(err) => write!(f, "{}", err),
Custom(err) => write!(f, "{}", err),
}
}
}
impl From<io::Error> for DocimaError {
fn from(err: io::Error) -> Self {
Self::IoError(err)
}
}
impl From<png::EncodingError> for DocimaError {
fn from(err: png::EncodingError) -> Self {
Self::PngEncodingError(err)
}
}
impl From<Box<dyn std::error::Error>> for DocimaError {
fn from(err: Box<dyn std::error::Error>) -> Self {
Self::StdError(err)
}
}