From 7d93f8f2533f19d0db0248c48ea7a469ec4f9e73 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Sun, 31 Jan 2021 00:11:10 +0000 Subject: [PATCH] daemon: wip macro for api routes Signed-off-by: Ian Jackson --- daemon/api.rs | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/daemon/api.rs b/daemon/api.rs index eea0cdce..def92c25 100644 --- a/daemon/api.rs +++ b/daemon/api.rs @@ -173,16 +173,31 @@ fn api_piece_op(form : Json>) "" } -#[derive(Debug,Serialize,Deserialize)] -struct ApiPieceGrab { -} -#[post("/_/api/grab", format="json", data="
")] -#[throws(OER)] -fn api_grab(form : Json>) - -> impl response::Responder<'static> { - api_piece_op(form)? +macro_rules! api_route { + { $fn:ident, $path:expr, + struct $form:ident $body:tt + $( $impl:tt )* + } => { + #[derive(Debug,Serialize,Deserialize)] + struct $form $body + + #[post($path, format="json", data="")] + #[throws(OER)] + fn $fn(form : Json>) + -> impl response::Responder<'static> { + api_piece_op(form)? + } + + impl ApiPieceOp for $form { + $( $impl )* + } + } } -impl ApiPieceOp for ApiPieceGrab { + +api_route!{ + api_grab, "/_/api/grab", + struct ApiPieceGrab { + } #[throws(ApiPieceOpError)] fn op(&self, a: ApiPieceOpArgs) -> PieceUpdateFromOp { let ApiPieceOpArgs { gs,player,piece,p,lens, .. } = a; -- 2.30.2