From 93b64b90ce426e6d1aa91d473265ec5dfde97b71 Mon Sep 17 00:00:00 2001 From: Scott Mabin Date: Sun, 31 Dec 2023 14:14:32 +0000 Subject: [PATCH] Extend the task macro to allow cfging arguments away --- embassy-executor-macros/src/macros/task.rs | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/embassy-executor-macros/src/macros/task.rs b/embassy-executor-macros/src/macros/task.rs index 5161e1020..1efb2788b 100644 --- a/embassy-executor-macros/src/macros/task.rs +++ b/embassy-executor-macros/src/macros/task.rs @@ -49,7 +49,7 @@ pub fn run(args: &[NestedMeta], f: syn::ItemFn) -> Result Result match t.pat.as_mut() { syn::Pat::Ident(id) => { - arg_names.push(id.ident.clone()); id.mutability = None; + args.push((id.clone(), t.attrs.clone())); } _ => { ctxt.error_spanned_by(arg, "pattern matching in task arguments is not yet supported"); @@ -79,13 +79,24 @@ pub fn run(args: &[NestedMeta], f: syn::ItemFn) -> Result ::embassy_executor::SpawnToken { type Fut = impl ::core::future::Future + 'static; const POOL_SIZE: usize = #pool_size; static POOL: ::embassy_executor::raw::TaskPool = ::embassy_executor::raw::TaskPool::new(); - unsafe { POOL._spawn_async_fn(move || #task_inner_ident(#(#arg_names,)*)) } + unsafe { POOL._spawn_async_fn(move || #task_inner_ident(#(#full_args,)*)) } } }; #[cfg(not(feature = "nightly"))] @@ -93,7 +104,7 @@ pub fn run(args: &[NestedMeta], f: syn::ItemFn) -> Result ::embassy_executor::SpawnToken { const POOL_SIZE: usize = #pool_size; static POOL: ::embassy_executor::_export::TaskPoolRef = ::embassy_executor::_export::TaskPoolRef::new(); - unsafe { POOL.get::<_, POOL_SIZE>()._spawn_async_fn(move || #task_inner_ident(#(#arg_names,)*)) } + unsafe { POOL.get::<_, POOL_SIZE>()._spawn_async_fn(move || #task_inner_ident(#(#full_args,)*)) } } };