zarust 0.2.1

Rust implementation of the ZArchive format
Documentation
use std::{fmt, io};

/// An error produced while reading or writing a ZArchive.
#[derive(Debug)]
pub enum Error {
    Io(io::Error),
    InvalidArchive(&'static str),
    InvalidPath(&'static str),
    DuplicatePath,
    NotAFile,
    NotADirectory,
    NameTooLong,
    ArchiveTooLarge,
}

impl fmt::Display for Error {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self {
            Self::Io(error) => write!(f, "I/O error: {error}"),
            Self::InvalidArchive(reason) => write!(f, "invalid ZArchive: {reason}"),
            Self::InvalidPath(reason) => write!(f, "invalid archive path: {reason}"),
            Self::DuplicatePath => f.write_str("an entry with that path already exists"),
            Self::NotAFile => f.write_str("the archive entry is not a file"),
            Self::NotADirectory => f.write_str("the archive entry is not a directory"),
            Self::NameTooLong => f.write_str("an archive path component exceeds 32,767 bytes"),
            Self::ArchiveTooLarge => f.write_str("the archive exceeds a format limit"),
        }
    }
}

impl std::error::Error for Error {
    fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
        match self {
            Self::Io(error) => Some(error),
            _ => None,
        }
    }
}

impl From<io::Error> for Error {
    fn from(error: io::Error) -> Self {
        Self::Io(error)
    }
}

pub type Result<T> = std::result::Result<T, Error>;