diff options
author | 2023-01-10 21:03:10 +0100 | |
---|---|---|
committer | 2023-03-01 00:33:30 +0100 | |
commit | d6d58b0eb88242cf63724e1420bd29f8a4489916 (patch) | |
tree | d797b67b381947cc375d9c89cdc15d0cc98dee1a /macros/src/syntax/parse/util.rs | |
parent | cd790a94286cdc307d399b7f7a43e305e90de5bf (diff) | |
download | rtic-d6d58b0eb88242cf63724e1420bd29f8a4489916.tar.gz rtic-d6d58b0eb88242cf63724e1420bd29f8a4489916.tar.zst rtic-d6d58b0eb88242cf63724e1420bd29f8a4489916.zip |
Async tasks can now take arguments at spawn again
Diffstat (limited to 'macros/src/syntax/parse/util.rs')
-rw-r--r-- | macros/src/syntax/parse/util.rs | 30 |
1 files changed, 20 insertions, 10 deletions
diff --git a/macros/src/syntax/parse/util.rs b/macros/src/syntax/parse/util.rs index 900ef9d6..5a5e0c0e 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<LocalRes Ok(resources) } -pub fn parse_inputs(inputs: Punctuated<FnArg, Token![,]>, name: &str) -> Option<Box<Pat>> { +type ParseInputResult = Option<(Box<Pat>, Result<Vec<PatType>, FnArg>)>; + +pub fn parse_inputs(inputs: Punctuated<FnArg, Token![,]>, 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::<Result<Vec<_>, _>>(); + + Some((first.pat, rest)) + } else { + None } } - } - None + _ => None, + } } pub fn type_is_bottom(ty: &ReturnType) -> bool { |