}
struct ToRgbIter<'a, T> where T: AsPrimitive<u8> {
- iter: Box<&'a mut dyn Iterator<Item = T>>
+ iter: &'a mut dyn Iterator<Item = T>
}
impl<'a, T: AsPrimitive<u8>> ToRgbIter<'a, T> {
- fn new(data: &'a mut (dyn Iterator<Item = T>)) -> ToRgbIter<T> {
- ToRgbIter { iter: Box::new(data) }
+ fn new(iter: &'a mut (dyn Iterator<Item = T>)) -> ToRgbIter<T> {
+ ToRgbIter { iter }
}
}
type Item = Rgb<u8>;
fn next(&mut self) -> Option<Rgb<u8>> {
if let Some(r) = self.iter.next() {
- let g = self.iter.next().unwrap_or(T::zero());
- let b = self.iter.next().unwrap_or(T::zero());
+ let g = self.iter.next().unwrap_or_else(T::zero);
+ let b = self.iter.next().unwrap_or_else(T::zero);
Some(Rgb([r.as_(), g.as_(), b.as_()]))
}
else {
Some(pixel) => pixel,
None => {
pixels = canvas.img.pixels_mut().skip(0);
- pixels.next().ok_or(ImageError::dimension_error())?
+ pixels.next().ok_or_else(ImageError::dimension_error)?
}
};
dp.0 = sp.0;
}
}?;
- Ok(canvas_option.insert(f(canvas, percent_decode_str(&data).into_iter().borrow_mut())?))
+ Ok(canvas_option.insert(f(canvas, percent_decode_str(data).into_iter().borrow_mut())?))
}
fn make_png(dim_x: u32, dim_y: u32, scale: u32, data: &mut dyn Iterator<Item = u8>) -> Result<Cursor<Vec<u8>>, ImageError> {
#[get("/gen/0/{data}")]
async fn img_gen0(req: HttpRequest) -> Result<impl Responder> {
- let data = req.uri().path().split("/").skip(3).next().unwrap();
- let cursor = make_png(32, 32, 16, percent_decode_str(&data).into_iter().borrow_mut())?;
+ let data = req.uri().path().split('/').nth(3).unwrap();
+ let cursor = make_png(32, 32, 16, percent_decode_str(data).into_iter().borrow_mut())?;
Ok(HttpResponse::build(StatusCode::OK)
.content_type("image/png")
.body(cursor.into_inner()))
#[get("/gen/1/{dim_x}/{dim_y}/{scale}/{data}")]
async fn img_gen1(req: HttpRequest, path: web::Path<(u32, u32, u32)>) -> Result<impl Responder> {
let (dim_x, dim_y, scale) = path.into_inner();
- let data = req.uri().path().split("/").skip(6).next().unwrap();
- let cursor = make_png(dim_x, dim_y, scale, percent_decode_str(&data).into_iter().borrow_mut())?;
+ let data = req.uri().path().split('/').nth(6).unwrap();
+ let cursor = make_png(dim_x, dim_y, scale, percent_decode_str(data).into_iter().borrow_mut())?;
Ok(HttpResponse::build(StatusCode::OK)
.content_type("image/png")
.body(cursor.into_inner()))
#[get("/pgen/0/{data}")]
async fn img_pgen0(req: HttpRequest, canvas0: web::Data<Arc<Mutex<Canvas0>>>) -> Result<impl Responder> {
- let data = req.uri().path().split("/").skip(3).next().unwrap();
+ let data = req.uri().path().split('/').nth(3).unwrap();
let scale = 16;
let img: RgbImage = ({
let canvas_option = &mut *canvas0.lock().unwrap();
#[get("/pgen/1/{dim_x}/{dim_y}/{scale}/{data}")]
async fn img_pgen1(req: HttpRequest, path: web::Path<(u32, u32, u32)>, canvas1: web::Data<Arc<Mutex<Canvas1>>>) -> Result<impl Responder> {
let (dim_x, dim_y, scale) = path.into_inner();
- let data = req.uri().path().split("/").skip(6).next().unwrap();
+ let data = req.uri().path().split('/').nth(6).unwrap();
let img: RgbImage = ({
let canvas_option = &mut *canvas1.lock().unwrap();
Ok(apply_to_canvas( |c, d| to_canvasresult(rgb_encode_to_canvas(c, d)), &mut canvas_option.0, Some((dim_x, dim_y)), data)?.img.clone())
1 => canvas1.lock().unwrap().0.take(),
2 => canvas2.lock().unwrap().0.take(),
_ => None
- }.ok_or_else( || CanvasError::NotExists )?;
+ }.ok_or(CanvasError::NotExists)?;
Ok(HttpResponse::build(StatusCode::OK)
.body(format!("Canvas {} dropped.", canvas_id)))
}