From 3c92e88164db6a94177fb4adeb18c80dffc377e4 Mon Sep 17 00:00:00 2001 From: Daniel Schadt Date: Thu, 12 Dec 2019 02:16:27 +0100 Subject: remove quick_error quick_error used the deprecated Error::cause interface, therefore we want to use our own error enums with proper methods. --- src/render.rs | 42 ++++++++++++++++++++++++++++++------------ 1 file changed, 30 insertions(+), 12 deletions(-) (limited to 'src/render.rs') diff --git a/src/render.rs b/src/render.rs index 90eff14..9b71e18 100644 --- a/src/render.rs +++ b/src/render.rs @@ -7,20 +7,38 @@ use image::{ use imageproc::{drawing, rect::Rect}; use num_traits::NumCast; use rusttype::{Font, Scale, SharedBytes}; +use std::{error::Error, fmt}; -quick_error! { - #[derive(Debug)] - pub enum RenderError { - ApiError(err: ApiError) { - cause(err) - from() - } - ImageError(err: image::ImageError) { - cause(err) - from() +#[derive(Debug)] +pub enum RenderError { + ApiError(ApiError), + ImageError(image::ImageError), + EmptyBuild, +} + +error_froms! { RenderError, + err: ApiError => RenderError::ApiError(err), + err: image::ImageError => RenderError::ImageError(err), +} + +impl fmt::Display for RenderError { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + match *self { + RenderError::ApiError(_) => write!(f, "error accessing the API"), + RenderError::ImageError(_) => write!(f, "image processing error"), + RenderError::EmptyBuild => { + write!(f, "the build template contains nothing worth rendering") + } } - EmptyBuild { - description("The build template contains nothing worth rendering") + } +} + +impl Error for RenderError { + fn source(&self) -> Option<&(dyn Error + 'static)> { + match *self { + RenderError::ApiError(ref err) => Some(err), + RenderError::ImageError(ref err) => Some(err), + _ => None, } } } -- cgit v1.2.3