1use std::io;
4
5pub type Result<T> = std::result::Result<T, SZipError>;
7
8#[derive(Debug)]
10pub enum SZipError {
11 Io(io::Error),
13 InvalidFormat(String),
15 EntryNotFound(String),
17 UnsupportedCompression(u16),
19 #[cfg(feature = "encryption")]
21 EncryptionError(String),
22 #[cfg(feature = "encryption")]
24 IncorrectPassword,
25}
26
27impl std::fmt::Display for SZipError {
28 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
29 match self {
30 SZipError::Io(e) => write!(f, "I/O error: {}", e),
31 SZipError::InvalidFormat(msg) => write!(f, "Invalid ZIP format: {}", msg),
32 SZipError::EntryNotFound(name) => write!(f, "Entry not found: {}", name),
33 SZipError::UnsupportedCompression(method) => {
34 write!(f, "Unsupported compression method: {}", method)
35 }
36 #[cfg(feature = "encryption")]
37 SZipError::EncryptionError(msg) => write!(f, "Encryption error: {}", msg),
38 #[cfg(feature = "encryption")]
39 SZipError::IncorrectPassword => write!(f, "Incorrect password"),
40 }
41 }
42}
43
44impl std::error::Error for SZipError {}
45
46impl From<io::Error> for SZipError {
47 fn from(err: io::Error) -> Self {
48 SZipError::Io(err)
49 }
50}