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
use std::error::Error as StdError;
use std::fmt;
use std::io;
#[cfg(feature = "zip")]
use zip_::result::ZipError;
pub type Result<T> = std::result::Result<T, Error>;
#[derive(Debug)]
pub enum Error {
FileNotFound,
Io(io::Error),
Utf8,
#[cfg(feature = "zip")]
UnsupportedZip,
#[cfg(feature = "zip")]
InvalidZip,
}
#[doc(hidden)]
impl From<io::Error> for Error {
fn from(err: io::Error) -> Self {
match err.kind() {
io::ErrorKind::NotFound => Error::FileNotFound,
_ => Error::Io(err),
}
}
}
#[doc(hidden)]
#[cfg(feature = "zip")]
impl From<ZipError> for Error {
fn from(e: ZipError) -> Self {
match e {
ZipError::Io(e) => Error::Io(e),
ZipError::FileNotFound => Error::FileNotFound,
ZipError::InvalidArchive(_) => Error::InvalidZip,
ZipError::UnsupportedArchive(_) => Error::UnsupportedZip,
}
}
}