async_deflate_zip/
error.rs1use std::fmt;
4use std::io;
5
6#[derive(Debug)]
8pub enum ZipError {
9 Io(io::Error),
11
12 FieldTooLong {
14 field: &'static str,
16 len: usize,
18 max: usize,
20 },
21
22 Poisoned(String),
25
26 InvalidState(String),
28}
29
30impl fmt::Display for ZipError {
31 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
32 match self {
33 Self::Io(e) => write!(f, "I/O error: {e}"),
34 Self::FieldTooLong { field, len, max } => {
35 write!(f, "{field} too long: {len} bytes (max {max})")
36 }
37 Self::Poisoned(msg) => write!(f, "archive corrupted: {msg}"),
38 Self::InvalidState(msg) => write!(f, "invalid state: {msg}"),
39 }
40 }
41}
42
43impl std::error::Error for ZipError {
44 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
45 match self {
46 Self::Io(e) => Some(e),
47 _ => None,
48 }
49 }
50}
51
52impl From<io::Error> for ZipError {
53 fn from(err: io::Error) -> Self {
54 Self::Io(err)
55 }
56}
57
58impl From<ZipError> for io::Error {
61 fn from(err: ZipError) -> Self {
62 match err {
63 ZipError::Io(e) => e,
64 ZipError::FieldTooLong { .. } => io::Error::new(io::ErrorKind::InvalidInput, err),
65 ZipError::Poisoned(_) => io::Error::other(err),
66 ZipError::InvalidState(_) => io::Error::new(io::ErrorKind::InvalidInput, err),
67 }
68 }
69}