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
use std; use zip::result::ZipError; #[derive(Debug)] pub enum Error { Extract(String), Io(std::io::Error), Zip(ZipError), } impl std::fmt::Display for Error { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { use Error::*; match *self { Extract(ref s) => write!(f, "ExtractError: {}", s), Io(ref e) => write!(f, "IoError: {}", e), Zip(ref e) => write!(f, "ZipError: {}", e), } } } impl std::error::Error for Error { fn description(&self) -> &str { "File Error" } fn cause(&self) -> Option<&dyn std::error::Error> { use Error::*; Some(match *self { Io(ref e) => e, _ => return None, }) } } impl From<std::io::Error> for Error { fn from(e: std::io::Error) -> Self { Error::Io(e) } } impl From<ZipError> for Error { fn from(e: ZipError) -> Self { Error::Zip(e) } }