diff options
| author | outfoxxed <[email protected]> | 2025-04-04 01:33:51 -0700 |
|---|---|---|
| committer | outfoxxed <[email protected]> | 2025-04-06 18:52:32 -0700 |
| commit | ef8d168df6fa1d8020d7490e4469d196a35077ce (patch) | |
| tree | c4edd4bebd6bae564006bfa45dbeacb2071fa533 /embassy-executor-macros/src/lib.rs | |
| parent | a44abaf7e4562fa5393087fd845bf0d02141325b (diff) | |
executor: add executor selection to #[embassy_executor::main]
Diffstat (limited to 'embassy-executor-macros/src/lib.rs')
| -rw-r--r-- | embassy-executor-macros/src/lib.rs | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/embassy-executor-macros/src/lib.rs b/embassy-executor-macros/src/lib.rs index 5f2182f10..8e737db6a 100644 --- a/embassy-executor-macros/src/lib.rs +++ b/embassy-executor-macros/src/lib.rs | |||
| @@ -173,3 +173,27 @@ pub fn main_std(args: TokenStream, item: TokenStream) -> TokenStream { | |||
| 173 | pub fn main_wasm(args: TokenStream, item: TokenStream) -> TokenStream { | 173 | pub fn main_wasm(args: TokenStream, item: TokenStream) -> TokenStream { |
| 174 | main::run(args.into(), item.into(), &main::ARCH_WASM).into() | 174 | main::run(args.into(), item.into(), &main::ARCH_WASM).into() |
| 175 | } | 175 | } |
| 176 | |||
| 177 | /// Creates a new `executor` instance and declares an application entry point for an unspecified architecture, spawning the corresponding function body as an async task. | ||
| 178 | /// | ||
| 179 | /// The following restrictions apply: | ||
| 180 | /// | ||
| 181 | /// * The function must accept exactly 1 parameter, an `embassy_executor::Spawner` handle that it can use to spawn additional tasks. | ||
| 182 | /// * The function must be declared `async`. | ||
| 183 | /// * The function must not use generics. | ||
| 184 | /// * Only a single `main` task may be declared. | ||
| 185 | /// | ||
| 186 | /// A user-defined entry macro and executor type must be provided via the `entry` and `executor` arguments of the `main` macro. | ||
| 187 | /// | ||
| 188 | /// ## Examples | ||
| 189 | /// Spawning a task: | ||
| 190 | /// ``` rust | ||
| 191 | /// #[embassy_executor::main(entry = "your_hal::entry", executor = "your_hal::Executor")] | ||
| 192 | /// async fn main(_s: embassy_executor::Spawner) { | ||
| 193 | /// // Function body | ||
| 194 | /// } | ||
| 195 | /// ``` | ||
| 196 | #[proc_macro_attribute] | ||
| 197 | pub fn main_unspecified(args: TokenStream, item: TokenStream) -> TokenStream { | ||
| 198 | main::run(args.into(), item.into(), &main::ARCH_UNSPECIFIED).into() | ||
| 199 | } | ||
