}
}
+#[derive(Debug)]
+enum CanvasError {
+ NotExists
+}
+
+impl Display for CanvasError {
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+ write!(f, "Canvas Error: see error_response() for more details")
+ }
+}
+
+impl ResponseError for CanvasError {
+ fn status_code(&self) -> StatusCode {
+ match &self {
+ CanvasError::NotExists => StatusCode::NOT_FOUND
+ }
+ }
+
+ fn error_response(&self) -> HttpResponse<BoxBody> {
+ match &self {
+ CanvasError::NotExists => HttpResponse::NotFound().body("Canvas does not exist.")
+ }
+ }
+}
+
struct ToRgbIter<'a, T> where T: AsPrimitive<u8> {
iter: Box<&'a mut dyn Iterator<Item = T>>
}
let tdim_y = 32 * scale;
let img: RgbImage = {
let canvas_option = &mut *canvas0.lock().unwrap();
- let canvas = canvas_option.take();
- let canvas = rgb_encode_to_canvas(canvas.expect("Canvas doesn't exist!"), percent_decode_str(&data).into_iter().borrow_mut())?;
+ let canvas = canvas_option.take().ok_or(CanvasError::NotExists)?;
+ let canvas = rgb_encode_to_canvas(canvas, percent_decode_str(&data).into_iter().borrow_mut())?;
canvas_option.insert(canvas).img.clone()
};
let img = resize(&img, tdim_x, tdim_y, FilterType::Nearest);