aboutsummaryrefslogtreecommitdiff
path: root/src/render.rs
diff options
context:
space:
mode:
authorDaniel Schadt <kingdread@gmx.de>2019-12-12 02:16:27 +0100
committerDaniel Schadt <kingdread@gmx.de>2019-12-12 02:16:27 +0100
commit3c92e88164db6a94177fb4adeb18c80dffc377e4 (patch)
treec2fdefbe04901df614a9753093d146f424d42a9c /src/render.rs
parenta6afa81d1d9f2dd7d10fe7c0555ae8a8a6d84867 (diff)
downloadkondou-3c92e88164db6a94177fb4adeb18c80dffc377e4.tar.gz
kondou-3c92e88164db6a94177fb4adeb18c80dffc377e4.tar.bz2
kondou-3c92e88164db6a94177fb4adeb18c80dffc377e4.zip
remove quick_error
quick_error used the deprecated Error::cause interface, therefore we want to use our own error enums with proper methods.
Diffstat (limited to 'src/render.rs')
-rw-r--r--src/render.rs42
1 files changed, 30 insertions, 12 deletions
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,
}
}
}