Skip to main content

workflow_rpc_macros/
lib.rs

1//! Procedural macros for `workflow-rpc` that build server and client method and
2//! notification handlers from closures or expressions, boxing and pinning their
3//! async bodies for registration with the RPC runtime.
4
5use proc_macro::TokenStream;
6use proc_macro_error3::proc_macro_error;
7use quote::quote;
8use syn::parse_macro_input;
9mod method;
10
11/// Constructs a server-side `workflow_rpc::server::Method` handler from a
12/// closure or expression, wrapping its body so it can serve a request-response
13/// RPC method.
14#[proc_macro]
15#[proc_macro_error]
16pub fn server_method(input: TokenStream) -> TokenStream {
17    let result = parse_macro_input!(input as method::Method);
18    let ts = quote! {
19        workflow_rpc::server::Method::new(#result)
20    };
21    ts.into()
22}
23
24/// Constructs a server-side `workflow_rpc::server::Notification` handler from
25/// a closure or expression, wrapping its body so it can handle inbound
26/// notifications from clients.
27#[proc_macro]
28#[proc_macro_error]
29pub fn server_notification(input: TokenStream) -> TokenStream {
30    let result = parse_macro_input!(input as method::Method);
31    let ts = quote! {
32        workflow_rpc::server::Notification::new(#result)
33    };
34    ts.into()
35}
36
37/// Constructs a client-side `workflow_rpc::client::Notification` handler from
38/// a closure or expression, wrapping its body so it can be registered to receive
39/// server-initiated notifications.
40#[proc_macro]
41#[proc_macro_error]
42pub fn client_notification(input: TokenStream) -> TokenStream {
43    let result = parse_macro_input!(input as method::Method);
44    let ts = quote! {
45        workflow_rpc::client::Notification::new(#result)
46    };
47    ts.into()
48}