From df7642e89bf96342505f18a9fed9844b3738aadd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kornel=20Lesi=C5=84ski?= Date: Fri, 1 Jun 2018 15:09:50 +0100 Subject: [PATCH] Error enum --- src/error.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/error.rs b/src/error.rs index 3a24980f..05a1b131 100644 --- a/src/error.rs +++ b/src/error.rs @@ -2,29 +2,29 @@ use std::error::Error; use std::fmt; #[derive(Debug, Clone)] -pub struct PngError { - description: String, +pub enum PngError { + Other(Box), } impl Error for PngError { - #[inline] + // deprecated fn description(&self) -> &str { - &self.description + "" } } impl fmt::Display for PngError { #[inline] fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "{}", self.description) + match self { + PngError::Other(s) => f.write_str(s), + } } } impl PngError { #[inline] pub fn new(description: &str) -> PngError { - PngError { - description: description.to_owned(), - } + PngError::Other(description.into()) } }