aboutsummaryrefslogtreecommitdiff
path: root/embassy-executor/src
diff options
context:
space:
mode:
authorMatthew Tran <[email protected]>2025-05-28 22:00:25 -0500
committerMatthew Tran <[email protected]>2025-05-28 23:37:17 -0500
commita4d4f62a1e0e808ec3dd93e282f517a2f8ad9fa5 (patch)
tree30529d5f171a70131885c840b6de040da6c5082a /embassy-executor/src
parent4766cc6f9756b54bb2e25be5ba5276538ea4917b (diff)
Allow `-> impl Future<Output = ()>` in #[task]
Diffstat (limited to 'embassy-executor/src')
-rw-r--r--embassy-executor/src/lib.rs47
1 files changed, 45 insertions, 2 deletions
diff --git a/embassy-executor/src/lib.rs b/embassy-executor/src/lib.rs
index dfe420bab..70abfcc3a 100644
--- a/embassy-executor/src/lib.rs
+++ b/embassy-executor/src/lib.rs
@@ -65,8 +65,17 @@ pub mod _export {
65 65
66 use crate::raw::TaskPool; 66 use crate::raw::TaskPool;
67 67
68 trait TaskReturnValue {}
69 impl TaskReturnValue for () {}
70 impl TaskReturnValue for Never {}
71
72 #[diagnostic::on_unimplemented(
73 message = "task function futures must resolve to `()`",
74 note = "use `async fn` or change the return type to `impl Future<Output = ()>`"
75 )]
76 #[allow(private_bounds)]
68 pub trait TaskFn<Args>: Copy { 77 pub trait TaskFn<Args>: Copy {
69 type Fut: Future + 'static; 78 type Fut: Future<Output: TaskReturnValue> + 'static;
70 } 79 }
71 80
72 macro_rules! task_fn_impl { 81 macro_rules! task_fn_impl {
@@ -74,7 +83,7 @@ pub mod _export {
74 impl<F, Fut, $($Tn,)*> TaskFn<($($Tn,)*)> for F 83 impl<F, Fut, $($Tn,)*> TaskFn<($($Tn,)*)> for F
75 where 84 where
76 F: Copy + FnOnce($($Tn,)*) -> Fut, 85 F: Copy + FnOnce($($Tn,)*) -> Fut,
77 Fut: Future + 'static, 86 Fut: Future<Output: TaskReturnValue> + 'static,
78 { 87 {
79 type Fut = Fut; 88 type Fut = Fut;
80 } 89 }
@@ -205,4 +214,38 @@ pub mod _export {
205 Align268435456: 268435456, 214 Align268435456: 268435456,
206 Align536870912: 536870912, 215 Align536870912: 536870912,
207 ); 216 );
217
218 #[allow(dead_code)]
219 trait HasOutput {
220 type Output;
221 }
222
223 impl<O> HasOutput for fn() -> O {
224 type Output = O;
225 }
226
227 #[allow(dead_code)]
228 type Never = <fn() -> ! as HasOutput>::Output;
229}
230
231/// Implementation details for embassy macros.
232/// Do not use. Used for macros and HALs only. Not covered by semver guarantees.
233#[doc(hidden)]
234#[cfg(feature = "nightly")]
235pub mod _export {
236 pub trait TaskReturnValue {}
237 impl TaskReturnValue for () {}
238 impl TaskReturnValue for Never {}
239
240 #[allow(dead_code)]
241 trait HasOutput {
242 type Output;
243 }
244
245 impl<O> HasOutput for fn() -> O {
246 type Output = O;
247 }
248
249 #[allow(dead_code)]
250 type Never = <fn() -> ! as HasOutput>::Output;
208} 251}