Macro method

Source
method!() { /* proc-macro */ }
Expand description

method!() macro for declaration of RPC method handlers

This macro simplifies creation of async method handler closures supplied to the RPC dispatch interface. An async method closure requires to be Boxed and its result must be Pinned, resulting in the following syntax:


interface.method(Box::new(MyOps::Method, Method::new(|req: MyReq|
    Box::pin(
        async move {
            // ...
            Ok(MyResp { })
        }
    )
)))

The method macro adds the required Box and Pin syntax, simplifying the declaration as follows:

interface.method(MyOps::Method, method!(
  | connection_ctx: ConnectionCtx,
    server_ctx: ServerContext,
    req: MyReq |
async move {
    // ...
    Ok(MyResp { })
}))