1use std::error::Error;
4use std::fmt;
5use std::io;
6
7pub type ZipResult<T> = Result<T, ZipError>;
9
10#[derive(Debug)]
12pub struct InvalidPassword;
13
14impl fmt::Display for InvalidPassword {
15 fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
16 write!(fmt, "invalid password for file in archive")
17 }
18}
19
20impl Error for InvalidPassword {}
21
22#[derive(Debug)]
24pub enum ZipError {
25 Io(io::Error),
27
28 InvalidArchive(&'static str),
30
31 UnsupportedArchive(&'static str),
33
34 FileNotFound,
36}
37
38impl From<io::Error> for ZipError {
39 fn from(err: io::Error) -> ZipError {
40 ZipError::Io(err)
41 }
42}
43
44impl fmt::Display for ZipError {
45 fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
46 match self {
47 ZipError::Io(err) => write!(fmt, "{}", err),
48 ZipError::InvalidArchive(err) => write!(fmt, "invalid Zip archive: {}", err),
49 ZipError::UnsupportedArchive(err) => write!(fmt, "unsupported Zip archive: {}", err),
50 ZipError::FileNotFound => write!(fmt, "specified file not found in archive"),
51 }
52 }
53}
54
55impl Error for ZipError {
56 fn source(&self) -> Option<&(dyn Error + 'static)> {
57 match self {
58 ZipError::Io(err) => Some(err),
59 _ => None,
60 }
61 }
62}
63
64impl ZipError {
65 pub const PASSWORD_REQUIRED: &'static str = "Password required to decrypt file";
77}
78
79impl From<ZipError> for io::Error {
80 fn from(err: ZipError) -> io::Error {
81 io::Error::new(io::ErrorKind::Other, err)
82 }
83}