use std::error::Error; use std::fmt::Display; use std::io; pub type ArchiveResult = Result>; #[derive(Debug)] pub enum ArchiveError { Io { error: io::Error }, Serde { message: String }, Archivator { module: String, error: E }, } impl From for ArchiveError { fn from(value: io::Error) -> Self { Self::Io { error: value } } } impl Display for ArchiveError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { Self::Io { error } => writeln!(f, "IO: {error}"), Self::Serde { message } => writeln!(f, "Serde: {message}"), Self::Archivator { module, error } => writeln!(f, "{module}: {error}"), } } } impl Error for ArchiveError {} impl serde::ser::Error for ArchiveError { fn custom(msg: T) -> Self { Self::Serde { message: msg.to_string(), } } } impl serde::de::Error for ArchiveError { fn custom(msg: T) -> Self { Self::Serde { message: msg.to_string(), } } }