11#![ feature( async_closure, noop_waker, async_fn_traits) ]
2+ #![ allow( unused) ]
23
34use std:: future:: Future ;
4- use std:: ops:: { AsyncFnMut , AsyncFnOnce } ;
5+ use std:: ops:: { AsyncFn , AsyncFnMut , AsyncFnOnce } ;
56use std:: pin:: pin;
67use std:: task:: * ;
78
@@ -17,6 +18,10 @@ pub fn block_on<T>(fut: impl Future<Output = T>) -> T {
1718 }
1819}
1920
21+ async fn call ( f : & mut impl AsyncFn ( i32 ) ) {
22+ f ( 0 ) . await ;
23+ }
24+
2025async fn call_mut ( f : & mut impl AsyncFnMut ( i32 ) ) {
2126 f ( 0 ) . await ;
2227}
@@ -26,10 +31,10 @@ async fn call_once(f: impl AsyncFnOnce(i32)) {
2631}
2732
2833async fn call_normal < F : Future < Output = ( ) > > ( f : & impl Fn ( i32 ) -> F ) {
29- f ( 0 ) . await ;
34+ f ( 1 ) . await ;
3035}
3136
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 ) {
3338 f ( 1 ) . await ;
3439}
3540
@@ -39,14 +44,16 @@ pub fn main() {
3944 let mut async_closure = async move |a : i32 | {
4045 println ! ( "{a} {b}" ) ;
4146 } ;
47+ call ( & mut async_closure) . await ;
4248 call_mut ( & mut async_closure) . await ;
4349 call_once ( async_closure) . await ;
4450
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} " ) ;
4854 } ;
4955 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 ;
5158 } ) ;
5259}
0 commit comments