zng_task_proc_macros/
any_all.rs

1//! Macro for `task::any!` or `task::all!` calls with more then 8 futures.
2
3use syn::{
4    Expr, Path, Token,
5    parse::{Parse, ParseStream},
6    parse_macro_input,
7    punctuated::Punctuated,
8};
9
10pub fn expand(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
11    let Input { macro_path, futs, .. } = parse_macro_input!(input as Input);
12
13    let fut_idents = (0..futs.len()).map(|i| ident!("__fut{i}"));
14    let futs = futs.iter();
15
16    let r = quote! {
17        #macro_path! {
18            #(#fut_idents: #futs;)*
19        }
20    };
21
22    r.into()
23}
24
25struct Input {
26    macro_path: Path,
27    _path_semi: Token![;],
28    futs: Punctuated<Expr, Token![,]>,
29}
30impl Parse for Input {
31    fn parse(input: ParseStream) -> syn::Result<Self> {
32        Ok(Input {
33            macro_path: input.parse()?,
34            _path_semi: input.parse()?,
35            futs: Punctuated::parse_separated_nonempty(input)?,
36        })
37    }
38}