error.rs 879 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. use std;
  2. use zip::result::ZipError;
  3. #[derive(Debug)]
  4. pub enum Error {
  5. Extract(String),
  6. Io(std::io::Error),
  7. Zip(ZipError),
  8. }
  9. impl std::fmt::Display for Error {
  10. fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
  11. use Error::*;
  12. match *self {
  13. Extract(ref s) => write!(f, "ExtractError: {}", s),
  14. Io(ref e) => write!(f, "IoError: {}", e),
  15. Zip(ref e) => write!(f, "ZipError: {}", e),
  16. }
  17. }
  18. }
  19. impl std::error::Error for Error {
  20. fn description(&self) -> &str {
  21. "File Error"
  22. }
  23. fn cause(&self) -> Option<&dyn std::error::Error> {
  24. use Error::*;
  25. Some(match *self {
  26. Io(ref e) => e,
  27. _ => return None,
  28. })
  29. }
  30. }
  31. impl From<std::io::Error> for Error {
  32. fn from(e: std::io::Error) -> Self {
  33. Error::Io(e)
  34. }
  35. }
  36. impl From<ZipError> for Error {
  37. fn from(e: ZipError) -> Self {
  38. Error::Zip(e)
  39. }
  40. }