-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherror.rs
More file actions
67 lines (60 loc) · 1.84 KB
/
Copy patherror.rs
File metadata and controls
67 lines (60 loc) · 1.84 KB
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
61
62
63
64
65
66
67
use std::fmt::Formatter;
#[derive(Debug)]
pub enum RefreshError {
IO(Box<dyn std::fmt::Debug + Send>),
InvalidZip(Box<zip::result::ZipError>),
InvalidData(Box<dyn std::fmt::Debug + Send>),
FileNotFound,
}
impl std::fmt::Display for RefreshError {
fn fmt(&self, f: &mut Formatter) -> std::fmt::Result {
let msg = match self {
RefreshError::IO(inner) => {
format!("IO: {:?}", inner)
},
RefreshError::InvalidZip(inner) => {
format!("Invalid zip data file: {}", inner)
},
RefreshError::InvalidData(inner) => {
format!("Invalid address data: {:?}", inner)
},
RefreshError::FileNotFound => {
"Could not find data file".into()
}
};
write!(f, "Refresh error: {}", msg)
}
}
impl From<diesel::result::Error> for RefreshError {
fn from(error: diesel::result::Error) -> Self {
RefreshError::IO(Box::new(error))
}
}
impl <E> From<actix_web::error::BlockingError<E>> for RefreshError
where
E: std::fmt::Debug + Send + 'static,
{
fn from(error: actix_web::error::BlockingError<E>) -> Self {
match error {
actix_web::error::BlockingError::Error(inner) =>
RefreshError::IO(Box::new(inner)),
_ =>
RefreshError::IO(Box::new(error)),
}
}
}
impl From<reqwest::Error> for RefreshError {
fn from(error: reqwest::Error) -> Self {
RefreshError::IO(Box::new(error))
}
}
impl From<zip::result::ZipError> for RefreshError {
fn from(error: zip::result::ZipError) -> Self {
RefreshError::InvalidZip(Box::new(error))
}
}
impl From<csv::Error> for RefreshError {
fn from(error: csv::Error) -> Self {
RefreshError::InvalidData(Box::new(error))
}
}