From d6d58b0eb88242cf63724e1420bd29f8a4489916 Mon Sep 17 00:00:00 2001 From: Emil Fresk Date: Tue, 10 Jan 2023 21:03:10 +0100 Subject: Async tasks can now take arguments at spawn again --- macros/src/syntax/parse/util.rs | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) (limited to 'macros/src/syntax/parse/util.rs') diff --git a/macros/src/syntax/parse/util.rs b/macros/src/syntax/parse/util.rs index 900ef9d..5a5e0c0 100644 --- a/macros/src/syntax/parse/util.rs +++ b/macros/src/syntax/parse/util.rs @@ -3,8 +3,8 @@ use syn::{ parse::{self, ParseStream}, punctuated::Punctuated, spanned::Spanned, - Abi, AttrStyle, Attribute, Expr, FnArg, ForeignItemFn, Ident, ItemFn, Pat, Path, PathArguments, - ReturnType, Token, Type, Visibility, + Abi, AttrStyle, Attribute, Expr, FnArg, ForeignItemFn, Ident, ItemFn, Pat, PatType, Path, + PathArguments, ReturnType, Token, Type, Visibility, }; use crate::syntax::{ @@ -231,19 +231,29 @@ pub fn parse_local_resources(content: ParseStream<'_>) -> parse::Result, name: &str) -> Option> { +type ParseInputResult = Option<(Box, Result, FnArg>)>; + +pub fn parse_inputs(inputs: Punctuated, name: &str) -> ParseInputResult { let mut inputs = inputs.into_iter(); - if let Some(FnArg::Typed(first)) = inputs.next() { - if type_is_path(&first.ty, &[name, "Context"]) { - // No more inputs - if inputs.next().is_none() { - return Some(first.pat); + match inputs.next() { + Some(FnArg::Typed(first)) => { + if type_is_path(&first.ty, &[name, "Context"]) { + let rest = inputs + .map(|arg| match arg { + FnArg::Typed(arg) => Ok(arg), + _ => Err(arg), + }) + .collect::, _>>(); + + Some((first.pat, rest)) + } else { + None } } - } - None + _ => None, + } } pub fn type_is_bottom(ty: &ReturnType) -> bool { -- cgit v1.2.3