1
1
#![ feature( async_closure, noop_waker, async_fn_traits) ]
2
+ #![ allow( unused) ]
2
3
3
4
use std:: future:: Future ;
4
- use std:: ops:: { AsyncFnMut , AsyncFnOnce } ;
5
+ use std:: ops:: { AsyncFn , AsyncFnMut , AsyncFnOnce } ;
5
6
use std:: pin:: pin;
6
7
use std:: task:: * ;
7
8
@@ -17,6 +18,10 @@ pub fn block_on<T>(fut: impl Future<Output = T>) -> T {
17
18
}
18
19
}
19
20
21
+ async fn call ( f : & mut impl AsyncFn ( i32 ) ) {
22
+ f ( 0 ) . await ;
23
+ }
24
+
20
25
async fn call_mut ( f : & mut impl AsyncFnMut ( i32 ) ) {
21
26
f ( 0 ) . await ;
22
27
}
@@ -26,10 +31,10 @@ async fn call_once(f: impl AsyncFnOnce(i32)) {
26
31
}
27
32
28
33
async fn call_normal < F : Future < Output = ( ) > > ( f : & impl Fn ( i32 ) -> F ) {
29
- f ( 0 ) . await ;
34
+ f ( 1 ) . await ;
30
35
}
31
36
32
- async fn call_normal_once < F : Future < Output = ( ) > > ( f : impl FnOnce ( i32 ) -> F ) {
37
+ async fn call_normal_mut < F : Future < Output = ( ) > > ( f : & mut impl FnMut ( i32 ) -> F ) {
33
38
f ( 1 ) . await ;
34
39
}
35
40
@@ -39,14 +44,16 @@ pub fn main() {
39
44
let mut async_closure = async move |a : i32 | {
40
45
println ! ( "{a} {b}" ) ;
41
46
} ;
47
+ call ( & mut async_closure) . await ;
42
48
call_mut ( & mut async_closure) . await ;
43
49
call_once ( async_closure) . await ;
44
50
45
- // No-capture closures implement `Fn`.
46
- let async_closure = async move |a : i32 | {
47
- println ! ( "{a}" ) ;
51
+ let b = 2i32 ;
52
+ let mut async_closure = async |a : i32 | {
53
+ println ! ( "{a} {b} " ) ;
48
54
} ;
49
55
call_normal ( & async_closure) . await ;
50
- call_normal_once ( async_closure) . await ;
56
+ call_normal_mut ( & mut async_closure) . await ;
57
+ call_once ( async_closure) . await ;
51
58
} ) ;
52
59
}
0 commit comments