Skip to main content

workflow_task_macros/
lib.rs

1//! Procedural macros backing the `workflow-task` crate, providing the
2//! [`task!`] and [`set_task!`] macros for declaring async task closures.
3
4use proc_macro::TokenStream;
5use proc_macro_error3::proc_macro_error;
6use quote::{ToTokens, quote};
7use syn::parse_macro_input;
8mod task;
9
10/// Constructs a `workflow_task::Task` from a closure or expression, wrapping
11/// the closure body so it is boxed and pinned as the task's async future.
12#[proc_macro]
13#[proc_macro_error]
14pub fn task(input: TokenStream) -> TokenStream {
15    let result = parse_macro_input!(input as task::Task);
16    let ts = quote! {
17        workflow_task::Task::new(#result)
18    };
19    ts.into()
20}
21
22/// Assigns a task closure to an existing task source by expanding to a
23/// `set_task_fn` call on the given target with the supplied closure.
24#[proc_macro]
25#[proc_macro_error]
26pub fn set_task(input: TokenStream) -> TokenStream {
27    let result = parse_macro_input!(input as task::SetTask);
28    let ts = result.to_token_stream();
29    ts.into()
30}