From: Ian Jackson Date: Sun, 31 Jan 2021 00:11:10 +0000 (+0000) Subject: daemon: wip macro for api routes X-Git-Tag: otter-0.4.0~617 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=7d93f8f2533f19d0db0248c48ea7a469ec4f9e73;p=otter.git daemon: wip macro for api routes Signed-off-by: Ian Jackson --- 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;