s_zip/
error.rs

1//! Error types for s-zip
2
3use std::io;
4
5/// Result type for s-zip operations
6pub type Result<T> = std::result::Result<T, SZipError>;
7
8/// Error types that can occur during ZIP operations
9#[derive(Debug)]
10pub enum SZipError {
11    /// I/O error
12    Io(io::Error),
13    /// Invalid ZIP format or structure
14    InvalidFormat(String),
15    /// Entry not found in ZIP archive
16    EntryNotFound(String),
17    /// Unsupported compression method
18    UnsupportedCompression(u16),
19}
20
21impl std::fmt::Display for SZipError {
22    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
23        match self {
24            SZipError::Io(e) => write!(f, "I/O error: {}", e),
25            SZipError::InvalidFormat(msg) => write!(f, "Invalid ZIP format: {}", msg),
26            SZipError::EntryNotFound(name) => write!(f, "Entry not found: {}", name),
27            SZipError::UnsupportedCompression(method) => {
28                write!(f, "Unsupported compression method: {}", method)
29            }
30        }
31    }
32}
33
34impl std::error::Error for SZipError {}
35
36impl From<io::Error> for SZipError {
37    fn from(err: io::Error) -> Self {
38        SZipError::Io(err)
39    }
40}