4 #![feature(type_alias_impl_trait)]
5 #![feature(closure_lifetime_binder)]
7 use std::future::Future;
9 trait AsyncFn<I, R>: FnMut(I) -> Self::Fut {
10 type Fut: Future<Output = R>;
13 impl<F, I, R, Fut> AsyncFn<I, R> for F
15 Fut: Future<Output = R>,
21 async fn call<C, R, F>(mut ctx: C, mut f: F) -> Result<R, ()>
23 F: for<'a> AsyncFn<&'a mut C, Result<R, ()>>,
26 match f(&mut ctx).await {
27 Ok(val) => return Ok(val),
34 impl<T> Cap<'_> for T {}
36 fn works(ctx: &mut usize) {
39 type Ret<'a, 'b: 'a> = impl Future<Output = Result<usize, ()>> + 'a + Cap<'b>;
41 let callback = for<'a, 'b> |c: &'a mut &'b mut usize| -> Ret<'a, 'b> {
51 fn doesnt_work_but_should(ctx: &mut usize) {
54 type Ret<'a, 'b: 'a> = impl Future<Output = Result<usize, ()>> + 'a + Cap<'b>;
56 call(ctx, for<'a, 'b> |c: &'a mut &'b mut usize| -> Ret<'a, 'b> {