From f8c3c93824645a807d28b760855b4676ea479720 Mon Sep 17 00:00:00 2001 From: Igor Tolmachev Date: Sat, 15 Jun 2024 03:30:50 +0900 Subject: Add simple zip reader --- src/error.rs | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 src/error.rs (limited to 'src/error.rs') diff --git a/src/error.rs b/src/error.rs new file mode 100644 index 0000000..6d7aba4 --- /dev/null +++ b/src/error.rs @@ -0,0 +1,35 @@ +use std::error::Error; +use std::fmt::Display; +use std::io; + +pub type ArchiveResult = Result>; + +#[derive(Debug)] +pub enum ArchiveError { + IO(io::Error), + Driver { name: &'static str, error: E }, +} + +impl From for ArchiveError { + fn from(value: io::Error) -> Self { + Self::IO(value) + } +} + +impl Display for ArchiveError { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + ArchiveError::IO(error) => write!(f, "{error}"), + ArchiveError::Driver { name, error } => write!(f, "{name}: {error}"), + } + } +} + +impl Error for ArchiveError { + fn source(&self) -> Option<&(dyn Error + 'static)> { + match self { + Self::IO(error) => Some(error), + _ => None, + } + } +} -- cgit v1.2.3