aboutsummaryrefslogtreecommitdiff
path: root/src/render.rs
diff options
context:
space:
mode:
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,
}
}
}