diff options
| author | Brendon Fallquist <[email protected]> | 2022-12-24 21:21:07 -0600 |
|---|---|---|
| committer | Brendon Fallquist <[email protected]> | 2022-12-24 21:21:07 -0600 |
| commit | 056eac998a5668c6737aafb44edc5bbe23e2df46 (patch) | |
| tree | 52df358b97ab75fabd0f258d34a5fdbf11b03bc0 | |
| parent | d1dd66cfcacd9a519188d7799d9c045673fff738 (diff) | |
Hide doc comments from inner function include doc comments on outer function
| -rw-r--r-- | embassy-macros/src/macros/task.rs | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/embassy-macros/src/macros/task.rs b/embassy-macros/src/macros/task.rs index 573776f8c..90d2cd893 100644 --- a/embassy-macros/src/macros/task.rs +++ b/embassy-macros/src/macros/task.rs | |||
| @@ -1,6 +1,7 @@ | |||
| 1 | use darling::FromMeta; | 1 | use darling::FromMeta; |
| 2 | use proc_macro2::TokenStream; | 2 | use proc_macro2::TokenStream; |
| 3 | use quote::{format_ident, quote}; | 3 | use quote::{format_ident, quote}; |
| 4 | use syn::{parse_quote, ItemFn}; | ||
| 4 | 5 | ||
| 5 | use crate::util::ctxt::Ctxt; | 6 | use crate::util::ctxt::Ctxt; |
| 6 | 7 | ||
| @@ -57,18 +58,25 @@ pub fn run(args: syn::AttributeArgs, f: syn::ItemFn) -> Result<TokenStream, Toke | |||
| 57 | task_inner.vis = syn::Visibility::Inherited; | 58 | task_inner.vis = syn::Visibility::Inherited; |
| 58 | task_inner.sig.ident = task_inner_ident.clone(); | 59 | task_inner.sig.ident = task_inner_ident.clone(); |
| 59 | 60 | ||
| 61 | let mut task_outer: ItemFn = parse_quote! { | ||
| 62 | #visibility fn #task_ident(#fargs) -> ::embassy_executor::SpawnToken<impl Sized> { | ||
| 63 | type Fut = impl ::core::future::Future + 'static; | ||
| 64 | static POOL: ::embassy_executor::raw::TaskPool<Fut, #pool_size> = ::embassy_executor::raw::TaskPool::new(); | ||
| 65 | unsafe { POOL._spawn_async_fn(move || #task_inner_ident(#(#arg_names,)*)) } | ||
| 66 | } | ||
| 67 | }; | ||
| 68 | |||
| 69 | task_outer.attrs.append(&mut task_inner.attrs.clone()); | ||
| 70 | |||
| 60 | let result = quote! { | 71 | let result = quote! { |
| 61 | // This is the user's task function, renamed. | 72 | // This is the user's task function, renamed. |
| 62 | // We put it outside the #task_ident fn below, because otherwise | 73 | // We put it outside the #task_ident fn below, because otherwise |
| 63 | // the items defined there (such as POOL) would be in scope | 74 | // the items defined there (such as POOL) would be in scope |
| 64 | // in the user's code. | 75 | // in the user's code. |
| 76 | #[doc(hidden)] | ||
| 65 | #task_inner | 77 | #task_inner |
| 66 | 78 | ||
| 67 | #visibility fn #task_ident(#fargs) -> ::embassy_executor::SpawnToken<impl Sized> { | 79 | #task_outer |
| 68 | type Fut = impl ::core::future::Future + 'static; | ||
| 69 | static POOL: ::embassy_executor::raw::TaskPool<Fut, #pool_size> = ::embassy_executor::raw::TaskPool::new(); | ||
| 70 | unsafe { POOL._spawn_async_fn(move || #task_inner_ident(#(#arg_names,)*)) } | ||
| 71 | } | ||
| 72 | }; | 80 | }; |
| 73 | 81 | ||
| 74 | Ok(result) | 82 | Ok(result) |
