}
}
+struct Canvas0(Option<Canvas>);
+struct Canvas1(Option<Canvas>);
+
#[get("/hello/{name}")]
async fn greet(name: web::Path<String>, req: HttpRequest) -> impl Responder {
println!("{:?}", req);
}
#[get("/pgen/0/{data}")]
-async fn img_pgen0(req: HttpRequest, canvas0: web::Data<Arc<Mutex<Option<Canvas>>>>) -> Result<impl Responder> {
+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 mut cursor = Cursor::new(Vec::new());
let scale = 16;
let img: RgbImage = ({
let canvas_option = &mut *canvas0.lock().unwrap();
- Ok(apply_to_canvas( |c, d| to_canvasresult(rgb_encode_to_canvas(c, d)), canvas_option, None, data)?.img.clone())
+ Ok(apply_to_canvas( |c, d| to_canvasresult(rgb_encode_to_canvas(c, d)), &mut canvas_option.0, None, data)?.img.clone())
} as Result<RgbImage, CanvasError>)?;
let (tdim_x, tdim_y) = img.dimensions();
let (tdim_x, tdim_y) = (tdim_x * scale, tdim_y * scale);
}
#[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<Option<Canvas>>>>) -> Result<impl Responder> {
+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 img: RgbImage = ({
let canvas_option = &mut *canvas1.lock().unwrap();
- Ok(apply_to_canvas( |c, d| to_canvasresult(rgb_encode_to_canvas(c, d)), canvas_option, Some((dim_x, dim_y)), data)?.img.clone())
+ 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())
} as Result<RgbImage, CanvasError>)?;
let (tdim_x, tdim_y) = img.dimensions();
let (tdim_x, tdim_y) = (tdim_x * scale, tdim_y * scale);
#[actix_web::main] // or #[tokio::main]
async fn main() -> std::io::Result<()> {
env_logger::init();
- let canvas0 = Arc::new(Mutex::new(Some(Canvas::new(32, 32))));
- let canvas1 = Arc::new(Mutex::new(None as Option<Canvas>));
+ let canvas0 = Arc::new(Mutex::new(Canvas0(Some(Canvas::new(32, 32)))));
+ let canvas1 = Arc::new(Mutex::new(Canvas1(None)));
HttpServer::new(move || {
App::new()
.service(greet)