| #![feature(type_alias_impl_trait)] |
| #![feature(closure_lifetime_binder)] |
| trait AsyncFn<I, R>: FnMut(I) -> Self::Fut { |
| type Fut: Future<Output = R>; |
| impl<F, I, R, Fut> AsyncFn<I, R> for F |
| async fn call<C, R, F>(mut ctx: C, mut f: F) -> Result<R, ()> |
| F: for<'a> AsyncFn<&'a mut C, Result<R, ()>>, |
| match f(&mut ctx).await { |
| Ok(val) => return Ok(val), |
| fn works(ctx: &mut usize) { |
| type Ret<'a, 'b: 'a> = impl Future<Output = Result<usize, ()>> + 'a + Cap<'b>; |
| let callback = for<'a, 'b> |c: &'a mut &'b mut usize| -> Ret<'a, 'b> { |
| fn doesnt_work_but_should(ctx: &mut usize) { |
| type Ret<'a, 'b: 'a> = impl Future<Output = Result<usize, ()>> + 'a + Cap<'b>; |
| call(ctx, for<'a, 'b> |c: &'a mut &'b mut usize| -> Ret<'a, 'b> { |