diff options
Diffstat (limited to 'embassy-executor/src/lib.rs')
| -rw-r--r-- | embassy-executor/src/lib.rs | 51 |
1 files changed, 49 insertions, 2 deletions
diff --git a/embassy-executor/src/lib.rs b/embassy-executor/src/lib.rs index dfe420bab..e174a0594 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 futures must resolve to `()` or `!`", | ||
| 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,42 @@ 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")] | ||
| 235 | pub mod _export { | ||
| 236 | #[diagnostic::on_unimplemented( | ||
| 237 | message = "task futures must resolve to `()` or `!`", | ||
| 238 | note = "use `async fn` or change the return type to `impl Future<Output = ()>`" | ||
| 239 | )] | ||
| 240 | pub trait TaskReturnValue {} | ||
| 241 | impl TaskReturnValue for () {} | ||
| 242 | impl TaskReturnValue for Never {} | ||
| 243 | |||
| 244 | #[allow(dead_code)] | ||
| 245 | trait HasOutput { | ||
| 246 | type Output; | ||
| 247 | } | ||
| 248 | |||
| 249 | impl<O> HasOutput for fn() -> O { | ||
| 250 | type Output = O; | ||
| 251 | } | ||
| 252 | |||
| 253 | #[allow(dead_code)] | ||
| 254 | type Never = <fn() -> ! as HasOutput>::Output; | ||
| 208 | } | 255 | } |
